程序代码:
Dim px(121) As Single, py(121) As Single '用来保存曲线数据的坐标值,程序中实时曲线通道为3.
Dim col As Integer '当前需绘制的点数
Dim pl As Integer '判断是否画动态曲线
Private Sub Command1_Click()
Timer2.Enabled = True
If Timer1.Enabled = True Then
Command1.Caption = "开始"
Timer1.Enabled = False
Else
Command1.Caption = "暂停"
Timer1.Enabled = True
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
Timer2.Enabled = False
End Sub
Private Sub Form_Load()
HScroll1.value = 900
Picture1.Scale (900, 0)-(1200, 300) '设置绘图区域坐标
End Sub
Private Sub HScroll1_Change()
Picture1.Cls '清空绘图区域
num = HScroll1.value '使绘图区域坐标和滚动条对应
Picture1.Scale (900 - (900 - num), 0)-(1200 - (900 - num), 300)
If pl >= 2 Then
Picture1.PSet (px(0), py(0))
For i = 1 To col
Picture1.Line -(px(i - 1), py(i - 1)), QBColor(2) ' 重绘曲线
Next i
End If
End Sub
Private Sub Timer1_Timer()
Picture1.Cls
If col < 31 Then
For i = 0 To col
px(i) = 900 + i * 10
py(i) = Val(List1.List(i)) '利用随机数模拟实际数据
Next i
col = col + 1
pl = pl + 1
ElseIf col < 121 Then
For j = 0 To col
py(j) = Val(List1.List(j))
px(j) = 1200 - 10 * (col - j) '如果数据点数》30 《121,数据的横坐标则用这个式子赋值
Next j
col = col + 1 '当数组装满时顺次前移,将数组第一个去掉
Else
For t = 0 To 119
py(t) = py(t + 1)
px(t) = 1200 - 10 * (col - t)
Next t
py(120) = Val(List1.List(i))
'数组的最后一个元素始终存放当前最新实时数据
End If
If pl >= 2 Then '在两个或两个以上的数据点时,开始画动态曲线
Picture1.PSet (px(0), py(0))
For i = 1 To col
Picture1.Line -(px(i - 1), py(i - 1)), QBColor(2)
Next i
End If
End Sub
Private Sub Timer2_Timer()
Dim value As Integer
Randomize
value = Int(200 * Rnd + 100)
List1.AddItem value
End Sub
程序代码如上,窗体和工程文件在附件儿里,希望大神来帮助啊!