回复 30楼 风吹过b
程序代码:
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 Timer1.Enabled = True End Sub Private Sub Command2_Click() End End Sub Private Sub Command3_Click() Timer2.Enabled = False Timer1.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 i = 0 To col py(i) = Val(List1.List(i)) px(i) = 1200 - 10 * (col - i) '如果数据点数》30 《121,数据的横坐标则用这个式子赋值 Next i 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(List1.ListCount - 1)) '数组的最后一个元素始终存放当前最新实时数据 End If If pl >= 2 Then '在两个或两个以上的数据点时,开始画动态曲 Picture1.PSet (px(0), py(0)) For i = 1 To col - 2 Picture1.Line -(px(i - 1), py(i - 1)), QBColor(2) Next i End If End Sub Private Sub Timer2_Timer() Dim value As Integer value = Int(100 * Rnd + 100) List1.AddItem value End Sub楼主,我这段程序已经差不多可以运行了,你可以帮我运行下,你会发现在曲线绘制一会儿后突然就变形了,变的不像刚开始那样的尖峰那样的了,然后再过一会儿又恢复成带尖的那种峰值了,你能帮我指出是程序哪儿段有问题吗,谢谢!