小弟,迷茫困惑中,请各位大虾多多指教!
csh79 2003-01-09 11:13:13 大家给看看这个程序的可行性,我的最终意图是要求从数据采集卡定时采集来的数据存在动态数组aa()中,然后再timer3中,从aa()中定时取其最大值和最小值。
其中,timer1.interval=5,timer3.interval=500,即每次丛数组里取100个数区最大最小值。
请大家多多提意见!
Function MaxValue(a() As Integer) As Integer
Dim i As Long, max As Integer, l As Integer, u As Integer
l = LBound(a): u = UBound(a)
max = a(l)
l = l + 1
For i = l To u
If a(i) > max Then max = a(i)
Next i
MaxValue = max
End Function
Function MinValue(a() As Integer) As Integer
Dim i As Long, min As Integer, l As Integer, u As Integer
l = LBound(a): u = UBound(a)
min = a(l)
l = l + 1
For i = l To u
If a(i) < min Then min = a(i)
Next i
MinValue = min
End Function
Private Sub Timer1_Timer()
Static n As Integer
n = LBound(aa)
rtn = GT_GetAdc(1, adc_data)
aa(n) = Int(200 * 10# * adc_data / 2048#)
Text1.Text = aa(n)
n = n + 1
End Sub
Private Sub Timer3_Timer()
Dim max11, min11 As Integer
Dim m As Integer
m = Timer3.Interval / Timer1.Interval
ReDim aa(m)
max11 = MaxValue(aa())
min11 = MinValue(aa())
Text4.Text = max11
Text5.Text = min11
End Sub