调试了好几天  仍然出现这种问题 头疼 
问题是:  为什么曲线总是以原点开始呢 而不是将的得到的点连成线呢  求指导源码: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

解决方案 »

  1.   

    你的程序贴全了没有???如果全了,那么没有看到你定义全局变量f,全局数组p(),q(),或者模块变量此外在timer1_timer里你定义来f,说明f不是全局变量或者模块变量还有在mscomm1_oncomm里,有  Exit Sub
      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
      

  2.   

    查阅msdn相对画线:Picture1.Line -(p(f), q(f))
      

  3.   

    都定义了全局变量 包括f timer里后来我去掉了在oncomm里我只是定义了个初始值  多谢提醒啊  谢谢
    恩 我在画线那是这么解决的
    Picture1.Line (p(f - 1), q(f - 1))-(p(f), q(f))
    变成了Picture1.Line—( p(f), q(f))就可以了