发表于:2005/5/31 15:27:00
#0楼
我接受的是十六进制数据,所以INPUTMODE定义为1,因为书上说INPUT属性不能直接赋值给字节数组,所以我定义了一个Variant的变量来接受数据,再赋给字节数组。但是i程序i运行总停在IF语句这里,并报下标越界,我参考过别人的程序都直接赋值字节数组,所以我搞不懂了,请各位老师指教。
以下是程序,请帮我看看
Public Sub read_data()
Dim zhancun1, zhancun2 As Integer
Dim shuju As Variant
Dim Time_out, I As Integer
Dim ERROR_COM As Boolean
Dim send(3) As Byte
Dim shuju1() As Byte
MSComm1.InBufferCount = 0 'clear off inbuffer
send(0) = &HFB: send(1) = &H1: send(2) = ((&HFB Xor &H1) And &H7F): sen(3) = &HFE
MSComm1.Output = send
'判断通讯错误
Do
DoEvents
Loop Until (MSComm1.InBufferCount >= 6)
shuju = MSComm1.Input
shuju1 = shuju
If Val(shuju1(0)) = Val(&HF0) And Val(shuju1(1)) = Val(&H1) Then
zhancun1 = shuju(3) '取出数据位
zhancun2 = shuju(4)
Elevator.floor = Revert(zhancun1)
Call explain(zhancun2)
End If
Call display_data1
End Sub
以下是程序,请帮我看看
Public Sub read_data()
Dim zhancun1, zhancun2 As Integer
Dim shuju As Variant
Dim Time_out, I As Integer
Dim ERROR_COM As Boolean
Dim send(3) As Byte
Dim shuju1() As Byte
MSComm1.InBufferCount = 0 'clear off inbuffer
send(0) = &HFB: send(1) = &H1: send(2) = ((&HFB Xor &H1) And &H7F): sen(3) = &HFE
MSComm1.Output = send
'判断通讯错误
Do
DoEvents
Loop Until (MSComm1.InBufferCount >= 6)
shuju = MSComm1.Input
shuju1 = shuju
If Val(shuju1(0)) = Val(&HF0) And Val(shuju1(1)) = Val(&H1) Then
zhancun1 = shuju(3) '取出数据位
zhancun2 = shuju(4)
Elevator.floor = Revert(zhancun1)
Call explain(zhancun2)
End If
Call display_data1
End Sub