VB中窗口不显示画线

2020-01-25 15:23发布

上周五刚接触VB,连菜鸟都不算,现在做一个最小的系统,就是下位传上来6个字节,VB用line画出来。我知道一般用pic,但是现在涉及到项目的一些问题,得现在窗口上显示。代码如下:
Dim flagup
Private Sub Command1_Click()
MSComm1.PortOpen = Faule
Unload Me
End Sub
Private Sub Form_Load()
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 512
MSComm1.InputMode = comInputModeBinary
MSComm1.Settings = "9600,n,8,1"
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
End Sub
Private Sub Form_Click()  '画坐标轴
    Dim X1 As Byte
     Dim X2 As Byte
      Dim Y1 As Byte
       Dim Y2 As Byte

End Sub
Private Sub shang_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim receivelen As Integer
    ReDim numup(0) As Byte   '发送一个字节

    numup(0) = &H12
    MSComm1.Output = numup
Select Case MSComm1.CommEvent   '接收一个字节
    Case comEvReceive
    ReDim receivenum(40) As Byte
     receivelen = MSComm1.InBufferCount  '定义字符串长度
    receivenum = MSComm1.Input
'For i = 0 To i = 5 Step 1
'   Text1.Text = receivenum(4)
End Select

       Dim X1 As Byte
     Dim X2 As Byte
      Dim Y1 As Byte
       Dim Y2 As Byte
   Cls                                    '画坐标轴
Form1.Scale (-120, 120)-(120, -120)
Line (-100, -100)-(100, -100): Line (-100, -100)-(-100, 100)
CurrentX = 100: CurrentY = -95: Print "Time"
CurrentX = -95: CurrentY = 100: Print "Val"
CurrentX = -90: CurrentY = -90: Print "Start"
For i = -100 To 100 Step 5
   CurrentX = i: CurrentY = -95: Line -(i, -100)
   CurrentX = i - 5: CurrentY = -105: Print (i + 100) / 5
Next i
For i = -95 To 100 Step 5
   CurrentX = -95: CurrentY = i: Line -(-100, i)
   CurrentX = -108: CurrentY = i: Print (i + 100) / 5
Next i


   Line (-20, -20)-(60, 50) '测试,只显示一根直线

    ' For i = 0 To i = 4 Step 1         '绘图
     ' X1 = 5 * i - 95
     '  Y1 = 5 * receivenum(i) - 95
      'X2 = 5 * (i + 1) - 95
      '  Y2 = 5 * receivenum(i + 1) - 95

       'Line (X1, Y1)-(X2, Y2)
       'Next i
End Sub
能检测到VB的却接收了正确的数据,但是就是不能绘制。单单 Line (-20, -20)-(60, 50) 是可以有条线的,但是一进了for循环就不行了,还提示 X1 = 5 * i - 95这行溢出。请各位大侠帮我看看神马问题吧,现在只能在窗口显示,不能调用pic。谢谢~


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
4条回答
lcw_swust
1楼-- · 2020-01-25 15:29
X1为BYTE型,不能为负数
窗体的autoredraw属性要设为true
marshallemon
2楼-- · 2020-01-25 15:52
上个图看看
cqfeiyu
3楼-- · 2020-01-25 16:59
自古二楼出真相
tairuibao
4楼-- · 2020-01-25 19:18
已经解决了,嘎嘎~

一周热门 更多>