调试了好几天 仍然出现这种问题 头疼
问题是: 为什么曲线总是以原点开始呢 而不是将的得到的点连成线呢 求指导源码:rivate Sub Mscomm1_oncomm()
Dim BytReceivedata(4) As String
Dim Frame() As Byte
Dim h As Byte
Dim i As Integer
Dim j As Integer
f = 0
Select Case MSComm1.CommEvent '事件发生
Case comEventRxOver '接收缓冲区溢出
Text1.Text = "" '为空
Exit Sub
Case comEvReceive '接收缓冲区有数据
Frame() = MSComm1.Input '读入到缓冲区
h = &H0
For j = 0 To 3 Step 1
h = h + Frame(j)
Next j
If h = Frame(4) And Hex(Frame(0)) = "68" Then '首部检查与和校验
If Hex(Frame(0)) = "68" Then '首部检查与和校验
For i = 0 To 4 '对5个帧检查,如果为一位数,则补0成为两位数
BytReceivedata(i) = Frame(i)
If Len(Hex(BytReceivedata(i))) = 1 Then '如果字节宽度为1,则前面加0变为两位
BytReceivedata(i) = "0" + Hex(BytReceivedata(i))
Else
BytReceivedata(i) = Hex(BytReceivedata(i)) '如果字节宽度为2,保持不变
End If
Next i
data = Val("&H " & BytReceivedata(2)) + Val("&H " & BytReceivedata(3)) * 0.1
Text1 = Text1 & data & " "
p(f) = data
If p(f) < 1 Then
Text2 = Text2 & 0 & " "
q(f) = 0
Else
Text2 = Text2 & (data * 2 - 2) & " "
q(f) = data * 2 - 2
End If
Else
Exit Sub
f = f + 1
End If
End If
End Select
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
End Sub
Private Sub draw()
Dim x As Single
Dim y As Single
Picture1.Scale (-0.5, 8)-(6, -0.5) ' 定义坐标系
'画坐标系
Picture1.ForeColor = RGB(200, 5, 200)
Picture1.DrawWidth = 1
Picture1.Line (0, 0)-(0, 7.5)
Picture1.Line (0, 0)-(5.5, 0)
Picture1.CurrentX = 5.5: Picture1.CurrentY = 0: Picture1.Print "V"
Picture1.CurrentX = 0: Picture1.CurrentY = 7.5: Picture1.Print "mm"
For i = 1 To 5 Step 1 ' 在X轴上标记坐标刻度
If i > 0 Then
Picture1.CurrentX = i: Picture1.CurrentY = -0.1: Picture1.Print i / 1 '分刻度
End If
Next i
For i = 1 To 6 Step 1 ' 在X轴上标记坐标刻度
If i > 0 Then
Picture1.CurrentX = -0.2: Picture1.CurrentY = i: Picture1.Print i / 1 '分刻度
End If
Next i
'位置坐标系
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 2
For y = 0 To 7 Step 0.1
Picture1.PSet (0, y)
Next y
'细分坐标轴等分化
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 4
Picture1.PSet (0, 1)
Picture1.PSet (0, 2)
Picture1.PSet (0, 3)
Picture1.PSet (0, 4)
Picture1.PSet (0, 5)
Picture1.PSet (0, 6)
Picture1.PSet (0, 7)
'绘制时间坐标轴,此需要处理编程电压形式
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 2
For x = 0 To 5 Step 0.1
Picture1.PSet (x, 0)
Next x
'分点等分坐标轴
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 4
Picture1.PSet (1, 0)
Picture1.PSet (2, 0)
Picture1.PSet (3, 0)
Picture1.PSet (4, 0)
Picture1.PSet (5, 0)
End Sub
'开始采集数据命令的的按钮
Private Sub Timer1_Timer()
Dim f As Integer
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 3
ReDim Preserve q(f + 1) '重新定义数组的位数
ReDim Preserve p(f + 1)
For f = 1 To f + 1
Picture1.Line (p(f - 1), q(f - 1))-(p(f), q(f))
If p(f) > 5 Then
Picture1.Cls
x = 0
Call draw
End If
Next f
End Sub
问题是: 为什么曲线总是以原点开始呢 而不是将的得到的点连成线呢 求指导源码:rivate Sub Mscomm1_oncomm()
Dim BytReceivedata(4) As String
Dim Frame() As Byte
Dim h As Byte
Dim i As Integer
Dim j As Integer
f = 0
Select Case MSComm1.CommEvent '事件发生
Case comEventRxOver '接收缓冲区溢出
Text1.Text = "" '为空
Exit Sub
Case comEvReceive '接收缓冲区有数据
Frame() = MSComm1.Input '读入到缓冲区
h = &H0
For j = 0 To 3 Step 1
h = h + Frame(j)
Next j
If h = Frame(4) And Hex(Frame(0)) = "68" Then '首部检查与和校验
If Hex(Frame(0)) = "68" Then '首部检查与和校验
For i = 0 To 4 '对5个帧检查,如果为一位数,则补0成为两位数
BytReceivedata(i) = Frame(i)
If Len(Hex(BytReceivedata(i))) = 1 Then '如果字节宽度为1,则前面加0变为两位
BytReceivedata(i) = "0" + Hex(BytReceivedata(i))
Else
BytReceivedata(i) = Hex(BytReceivedata(i)) '如果字节宽度为2,保持不变
End If
Next i
data = Val("&H " & BytReceivedata(2)) + Val("&H " & BytReceivedata(3)) * 0.1
Text1 = Text1 & data & " "
p(f) = data
If p(f) < 1 Then
Text2 = Text2 & 0 & " "
q(f) = 0
Else
Text2 = Text2 & (data * 2 - 2) & " "
q(f) = data * 2 - 2
End If
Else
Exit Sub
f = f + 1
End If
End If
End Select
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
End Sub
Private Sub draw()
Dim x As Single
Dim y As Single
Picture1.Scale (-0.5, 8)-(6, -0.5) ' 定义坐标系
'画坐标系
Picture1.ForeColor = RGB(200, 5, 200)
Picture1.DrawWidth = 1
Picture1.Line (0, 0)-(0, 7.5)
Picture1.Line (0, 0)-(5.5, 0)
Picture1.CurrentX = 5.5: Picture1.CurrentY = 0: Picture1.Print "V"
Picture1.CurrentX = 0: Picture1.CurrentY = 7.5: Picture1.Print "mm"
For i = 1 To 5 Step 1 ' 在X轴上标记坐标刻度
If i > 0 Then
Picture1.CurrentX = i: Picture1.CurrentY = -0.1: Picture1.Print i / 1 '分刻度
End If
Next i
For i = 1 To 6 Step 1 ' 在X轴上标记坐标刻度
If i > 0 Then
Picture1.CurrentX = -0.2: Picture1.CurrentY = i: Picture1.Print i / 1 '分刻度
End If
Next i
'位置坐标系
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 2
For y = 0 To 7 Step 0.1
Picture1.PSet (0, y)
Next y
'细分坐标轴等分化
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 4
Picture1.PSet (0, 1)
Picture1.PSet (0, 2)
Picture1.PSet (0, 3)
Picture1.PSet (0, 4)
Picture1.PSet (0, 5)
Picture1.PSet (0, 6)
Picture1.PSet (0, 7)
'绘制时间坐标轴,此需要处理编程电压形式
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 2
For x = 0 To 5 Step 0.1
Picture1.PSet (x, 0)
Next x
'分点等分坐标轴
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 4
Picture1.PSet (1, 0)
Picture1.PSet (2, 0)
Picture1.PSet (3, 0)
Picture1.PSet (4, 0)
Picture1.PSet (5, 0)
End Sub
'开始采集数据命令的的按钮
Private Sub Timer1_Timer()
Dim f As Integer
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 3
ReDim Preserve q(f + 1) '重新定义数组的位数
ReDim Preserve p(f + 1)
For f = 1 To f + 1
Picture1.Line (p(f - 1), q(f - 1))-(p(f), q(f))
If p(f) > 5 Then
Picture1.Cls
x = 0
Call draw
End If
Next f
End Sub
解决方案 »
- 有没有什么办法让两个过程齐头并进,同步执行?比如我有两个都是很长的循环过程,我想让他们完全同步开始,同步执行.
- 用FindFirstFile函数逐一打开一个文件夹中多个文件,如何得知其中一个文件的具体路径?
- 如何中间跳出循环
- 采鸟问的菜问题(参数传递)
- 求助VB关于注册表的问题~~在线等~~急
- vb解决sql里自动增长类型字段连续的问题?
- installshield做完安装无法安装在个别机器上 怎么办 在线等
- 散分了。
- 我接手一个项目要读一台地磅秤重时的重量,如何读地磅接口的数据.
- 在MDI工程中,若不打开子窗体,用SendKeys "{F1}"不能启动CHM帮助文件?
- 调用JS里unescape的问题
- 新人请老师指点
f = f + 1既然已经exitsub了,后面f=f+1怎么可以执行...想干什么?Private Sub Mscomm1_oncomm()
Dim BytReceivedata(4) As String
Dim Frame() As Byte
Dim h As Byte
Dim i As Integer
Dim j As Integer
f = 0
Select Case MSComm1.CommEvent '事件发生
Case comEventRxOver '接收缓冲区溢出
Text1.Text = "" '为空
Exit Sub
Case comEvReceive '接收缓冲区有数据
Frame() = MSComm1.Input '读入到缓冲区
h = &H0
For j = 0 To 3 Step 1
h = h + Frame(j)
Next j
If h = Frame(4) And Hex(Frame(0)) = "68" Then '首部检查与和校验
If Hex(Frame(0)) = "68" Then '首部检查与和校验
For i = 0 To 4 '对5个帧检查,如果为一位数,则补0成为两位数
BytReceivedata(i) = Frame(i)
If Len(Hex(BytReceivedata(i))) = 1 Then '如果字节宽度为1,则前面加0变为两位
BytReceivedata(i) = "0" + Hex(BytReceivedata(i))
Else
BytReceivedata(i) = Hex(BytReceivedata(i)) '如果字节宽度为2,保持不变
End If
Next i
Data = Val("&H " & BytReceivedata(2)) + Val("&H " & BytReceivedata(3)) * 0.1
Text1 = Text1 & Data & " "
p(f) = Data
If p(f) < 1 Then
Text2 = Text2 & 0 & " "
q(f) = 0
Else
Text2 = Text2 & (Data * 2 - 2) & " "
q(f) = Data * 2 - 2
End If
Else
Exit Sub
f = f + 1
End If
End If
End Select
MSComm1.OutBufferCount = 0
MSComm1.InBufferCount = 0
End Sub
Private Sub draw()
Dim x As Single
Dim y As Single
Picture1.Scale (-0.5, 8)-(6, -0.5) ' 定义坐标系
'画坐标系
Picture1.ForeColor = RGB(200, 5, 200)
Picture1.DrawWidth = 1
Picture1.Line (0, 0)-(0, 7.5)
Picture1.Line (0, 0)-(5.5, 0)
Picture1.CurrentX = 5.5: Picture1.CurrentY = 0: Picture1.Print "V"
Picture1.CurrentX = 0: Picture1.CurrentY = 7.5: Picture1.Print "mm"
For i = 1 To 5 Step 1 ' 在X轴上标记坐标刻度
If i > 0 Then
Picture1.CurrentX = i: Picture1.CurrentY = -0.1: Picture1.Print i / 1 '分刻度
End If
Next i
For i = 1 To 6 Step 1 ' 在X轴上标记坐标刻度
If i > 0 Then
Picture1.CurrentX = -0.2: Picture1.CurrentY = i: Picture1.Print i / 1 '分刻度
End If
Next i
'位置坐标系
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 2
For y = 0 To 7 Step 0.1
Picture1.PSet (0, y)
Next y
'细分坐标轴等分化
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 4
Picture1.PSet (0, 1)
Picture1.PSet (0, 2)
Picture1.PSet (0, 3)
Picture1.PSet (0, 4)
Picture1.PSet (0, 5)
Picture1.PSet (0, 6)
Picture1.PSet (0, 7)
'绘制时间坐标轴,此需要处理编程电压形式
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 2
For x = 0 To 5 Step 0.1
Picture1.PSet (x, 0)
Next x
'分点等分坐标轴
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 4
Picture1.PSet (1, 0)
Picture1.PSet (2, 0)
Picture1.PSet (3, 0)
Picture1.PSet (4, 0)
Picture1.PSet (5, 0)
End Sub
'开始采集数据命令的的按钮
Private Sub Timer1_Timer()
Dim f As Integer
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.DrawWidth = 3
ReDim Preserve q(f + 1) '重新定义数组的位数
ReDim Preserve p(f + 1)
For f = 1 To f + 1
Picture1.Line (p(f - 1), q(f - 1))-(p(f), q(f))
If p(f) > 5 Then
Picture1.Cls
x = 0
Call draw
End If
Next f
End Sub
恩 我在画线那是这么解决的
Picture1.Line (p(f - 1), q(f - 1))-(p(f), q(f))
变成了Picture1.Line—( p(f), q(f))就可以了