100分求一问题解决
程序要实现的功能很简单,我也写了一个模拟程序,可以发过去共同研究,我的qq:30926433
http://community.csdn.net/Expert/topic/5402/5402834.xml?temp=.2579004
[解决办法]
原来的程序写的比较乱, 模块化程度不够, 帮你重新写了一个, 最核心的功能已经完成了
在窗体上需要添加三个控件:
1. 一个名为picDraw的PictureBox控件
2. 一个名为tmrDataCreate的Timer控件
2. 一个名为tmrDraw的Timer控件
Option Explicit
Private Declare Function BitBlt Lib "gdi32 " (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Const ChannelNumber = 2 '通道数量
Const DataBufferSize = 10000 '通道数据缓冲区大小
Const ScreenScrollSize = 8 '屏幕滚动尺寸
Const RuleScaleSize = 30 '标尺上的温度最大值
Private Type TempData
AData(0 To DataBufferSize - 1) As Single
iStart As Integer
iEnd As Integer
End Type
Private ChannelData(0 To ChannelNumber - 1) As TempData '通道数据
Private ChannelColor(0 To ChannelNumber - 1) As Long '通道颜色
Private PrevData(0 To ChannelNumber - 1) As Single '用于通道作图的临时缓冲
'用于产生模拟数据的临时变量
Private RndDir(0 To ChannelNumber - 1) As Integer
Private RndCount(0 To ChannelNumber - 1) As Integer
Private RndData(0 To ChannelNumber - 1) As Single
Private Sub InitData()
Dim iLoop As Integer
For iLoop = 0 To ChannelNumber - 1
ChannelData(iLoop).iStart = 0
ChannelData(iLoop).iEnd = 0
PrevData(iLoop) = 0
RndDir(iLoop) = 0
RndCount(iLoop) = 0
RndData(iLoop) = 0
Next iLoop
ChannelColor(0) = vbRed
ChannelColor(1) = vbGreen
End Sub
Private Sub AddChannelData(ByVal iChannel As Integer, ByVal fData As Single)
Dim iTemp As Integer
With ChannelData(iChannel)
.AData(.iEnd) = fData
iTemp = (.iEnd + 1) Mod DataBufferSize
If iTemp <> .iStart Then .iEnd = iTemp
'iTemp = iStart意味着缓冲区已满, 在此只能舍弃最新的数据
End With
End Sub
Private Function GetChannelData(ByVal iChannel As Integer) As Single
GetChannelData = -9999 '-9999意味着没有新的数据
With ChannelData(iChannel)
If .iStart <> .iEnd Then
GetChannelData = .AData(.iStart)
.iStart = (.iStart + 1) Mod DataBufferSize
End If
End With
End Function
Private Sub DrawData(ByVal iChannel As Integer, ByVal AColor As Long)
Dim fData As Single
fData = GetChannelData(iChannel)
If fData <= -9999 Then fData = 0
picDraw.Line (picDraw.ScaleWidth - ScreenScrollSize - 1, picDraw.ScaleHeight / 2 - PrevData(iChannel) * (picDraw.ScaleHeight / RuleScaleSize / 2))- _
(picDraw.ScaleWidth - 1, picDraw.ScaleHeight / 2 - fData * (picDraw.ScaleHeight / RuleScaleSize / 2)), AColor
PrevData(iChannel) = fData
End Sub
Private Sub ScreenScroll()
BitBlt picDraw.hDC, 0, 0, picDraw.ScaleWidth - ScreenScrollSize + 1, picDraw.ScaleHeight - 1, picDraw.hDC, ScreenScrollSize - 1, 0, vbSrcCopy
picDraw.Line (picDraw.ScaleWidth - ScreenScrollSize + 1, 0)-(picDraw.ScaleWidth - 1, picDraw.ScaleHeight), picDraw.BackColor, BF
End Sub
Private Sub tmrDataCreate_Timer()
Dim iLoop As Integer
For iLoop = 0 To ChannelNumber - 1
If RndCount(iLoop) = 0 Then
RndDir(iLoop) = Sgn(Rnd - 0.5) '气温变化的方向
RndCount(iLoop) = Rnd * 10 + 5 '每种变化方向的连续变化次数
End If
RndData(iLoop) = RndData(iLoop) + Rnd * RndDir(iLoop)
RndCount(iLoop) = RndCount(iLoop) - 1
AddChannelData iLoop, RndData(iLoop)
Next iLoop
End Sub
Private Sub tmrDraw_Timer()
Dim iLoop As Integer
ScreenScroll
For iLoop = 0 To ChannelNumber - 1
DrawData iLoop, ChannelColor(iLoop)
Next iLoop
End Sub
Private Sub Form_Load()
picDraw.ScaleMode = vbPixels
InitData
Randomize Timer
tmrDataCreate.Interval = 200
tmrDataCreate.Enabled = True
tmrDraw.Interval = 200
tmrDraw.Enabled = True
End Sub
[解决办法]
jadeluo(秀峰),还有两个问题向你请教
1:你给的程序画线是从右向左的,怎么改成是从左向右的呢?
2:你用的是随机函数模拟的两条线,而我的是只有温度参数,你写的是两个参数阿,如何解决?For iLoop = 0 To ChannelNumber - 1
If RndCount(iLoop) = 0 Then
RndDir(iLoop) = Sgn(Rnd - 0.5) '气温变化的方向----参数1
RndCount(iLoop) = Rnd * 10 + 5 '每种变化方向的连续变化次数----参数2
End If
RndData(iLoop) = RndData(iLoop) + Rnd * RndDir(iLoop)
RndCount(iLoop) = RndCount(iLoop) - 1
AddChannelData iLoop, RndData(iLoop)
Next iLoop
如何把我的参数加入到你写的程序
问题解决就结贴,分不够,可以再加
[解决办法]
路过并接分
[解决办法]
接分并路过
[解决办法]
路过但不接分
[解决办法]
路过但不接分
[解决办法]
接分,帮楼主顶一个
[解决办法]
我也顶一下
[解决办法]
路过但不接分
[解决办法]
不路过 但接分