现在要VB将一个数组传送到下位机,但是无法实现,现在是我编的一些程序,望各位指出哪里有错误?
Private Sub Form_Load()
With Form1
     .MSComm1.CommPort = 1                    '使用COM3
     .MSComm1.Settings = "128000,N,8,1"         '设置通信口参数
     .MSComm1.InBufferSize = 1024 * 20           '设置MSComm1接收缓冲区为60字节
     .MSComm1.OutBufferSize = 1024             '设置MSComm1发送缓冲区为60字节
     .MSComm1.InputMode = comInputModeBinary  '设置接收数据模式为二进制形式
     .MSComm1.InputLen = 1                    '设置Input 一次从接收缓冲读取字节数为1
     .MSComm1.InBufferCount = 0               '清除接收缓冲区
     .MSComm1.OutBufferCount = 0              '清除发送缓冲区
     .MSComm1.RThreshold = xtime_temp                  '设置接收一个字节产生OnComm事件
     .MSComm1.PortOpen = True
End With
End SubPrivate Sub Command7_Click()
Dim i, position(0 To 11) As Integer
For i = 0 To 11
Next iposition(0) = OX00
position(1) = Hex(Val(Form4.wzbhblText.Text))
position(2) = OX01
position(3) = Hex(Val(Form4.wzbhjfText.Text))
position(4) = OX02
position(5) = Hex(Val(Form4.wzzxbfzText.Text))
position(6) = OX03
position(7) = Hex(Val(Form4.wzzxbzqText.Text))
position(8) = OX04
position(9) = Hex(Val(Form4.wzjyfzText.Text))
position(10) = OX05
position(11) = Hex(Val(Form4.wzjyzqText.Text))
Dim j, speed(0 To 15) As Integer
For j = 0 To 15
Next jspeed(0) = OX10
speed(1) = Hex(Val(Form3.zshblText.Text))
speed(2) = OX11
speed(3) = Hex(Val(Form3.zshjfText.Text))
speed(4) = OX12
speed(5) = Hex(Val(Form3.sdjyfzText.Text))
speed(6) = OX13
speed(7) = Hex(Val(Form3.sdjyzqText.Text))
speed(8) = OX14
speed(9) = Hex(Val(Form3.sdsjbfzText.Text))
speed(10) = OX15
speed(11) = Hex(Val(Form3.sdsjbzqText.Text))
speed(12) = OX16
speed(13) = Hex(Val(Form3.sdzxbfzText.Text))
speed(14) = OX17
speed(15) = Hex(Val(Form3.sdzxbzqText.Text))
Dim k, current(0 To 7) As Integer
For k = 0 To 7
Next kcurrent(0) = OX20
current(1) = Hex(Val(Form2.dlhblText.Text))
current(2) = OX21
current(3) = Hex(Val(Form2.dlhjfText.Text))
current(4) = OX22
current(5) = Hex(Val(Form2.dljyfzText.Text))
current(6) = OX23
current(7) = Hex(Val(Form2.dljyzqText.Text))
MSComm1.Output = position(i)
MSComm1.Output = speed(j)
MSComm1.Output = current(k)
Command7.Enabled = False
End Sub

解决方案 »

  1.   

    这是从哪里弄来的垃圾程序呀,不停的给整形数组赋值,还是字符串?还是OX....,咋不是XO,人头马呀.
    Dim k, current(0 To 7) As Integer
    current(0) = OX20
    current(1) = Hex(Val(Form2.dlhblText.Text))Dim i, position(0 To 11) As Integer
    position(0) = OX00
    position(1) = Hex(Val(Form4.wzbhblText.Text))Dim j, speed(0 To 15) As Integer
    speed(0) = OX10
    speed(1) = Hex(Val(Form3.zshblText.Text))大哥你是哪里来的呀,还是找本书好好看看,罗马可不是1天修的
      

  2.   

    看你的MSComm控件初始化没有什么问题,但你的发送就有问题了
    发送数组只需要把数组名写上就可以了。
      

  3.   

    http://download.csdn.net/source/1262066
      

  4.   

    0xYYYYY这样的形式是C里面的十六进制表现形式.VB里面,使用的是&H前缀.把你所有的0X换成&H.
      

  5.   

    还有个问题
    Hex(Val(Form4.wzbhblText.Text))
    是字符串,不是数值
    要将16进制字符串转换一下才能变数值
    如:
    Int("&H" & Hex(Val(Form4.wzbhblText.Text)))楼上也说了,还有就是 speed(0) = OX10  这种问题
    这样改  speed(0) = &H10
      

  6.   

    还有就是既然你的数据为 0x10 这类数据,表示一个字节的数据,为什么还要 Integer 来定义数组?
    用 Byte 不是更加合适吗?