回复 9楼 lowxiong
伟大的楼主,我咋给你分数啊,我第一次发帖,以前没有操作过这些东西
程序代码:
Dim px(121) As Single, py(121) As Single '用来保存曲线数据的坐标值,程序中实时曲线通道为3.
Dim col As Integer '当前需绘制的点数
Dim pl As Integer '判断是否画动态曲线
Dim num As Integer
Private Sub Command1_Click()
If col > 900 Then
MsgBox "超出采样数量!", vbExclamation, "提示"
Exit Sub
End If
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) '设置绘图区域坐标
col = 0
pl = 0
num = 0
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 = 0 To 30
px(i) = 900 + i * 10
py(i) = IIf(num < 31, Val(List1.List(i)), Val(List1.List(num - 30 + i)))
Picture1.Line -(px(i), py(i)), QBColor(2) ' 重绘曲线
Next i
End If
End Sub
Private Sub Timer1_Timer()
Picture1.Cls
If col > List1.ListCount Then
MsgBox "采样数量超出列表数量!", vbExclamation, "Error"
Timer1.Enabled = False
Command1.Caption = "开始"
Exit Sub
End If
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 <= 900 Then
For i = 0 To 30
py(i) = Val(List1.List(col - 30 + i))
px(i) = 900 + i * 10
Next i
col = col + 1
Else
Timer1.Enabled = False
Command1.Caption = "开始"
End If
If pl >= 2 Then '在两个或两个以上的数据点时,开始画动态曲线
Picture1.PSet (px(0), py(0))
For i = 0 To 30
Picture1.Line -(px(i), py(i)), QBColor(2)
Next i
HScroll1.value = col
End If
End Sub
Private Sub Timer2_Timer()
Dim value As Integer
Randomize
value = Int(200 * Rnd + 100)
List1.AddItem value
If List1.ListCount > 900 Then
Timer2.Enabled = False
End If
End Sub

