![]() |
#2
apull2013-05-16 12:27
|

Private Sub MSComm1_OnComm()
Dim BytReceived() As Byte
Dim strBuff As Variant
Select Case Case 2
MSComm1.InputLen = 0
strBuff = MSComm1.Input
BytReceived() = strBuff
Dim i As Long
For i = 0 To UBound(BytReceived)
Debug.Print BytReceived(i)
Next
If i <= 2 Then
Text2 = BytReceived(0)
BytReceived(0) = 0
Else
tongyi = BytReceived(0)
BytReceived(0) = 0
fandui = BytReceived(2)
BytReceived(2) = 0
qiquan = BytReceived(4)
BytReceived(4) = 0
End If
End Select
我这段代码那里有问题 为什么运行时经常出现 错误9,“下标越界” 调试时总指在qiquan = BytReceived(4)这一行Dim BytReceived() As Byte
Dim strBuff As Variant
Select Case Case 2
MSComm1.InputLen = 0
strBuff = MSComm1.Input
BytReceived() = strBuff
Dim i As Long
For i = 0 To UBound(BytReceived)
Debug.Print BytReceived(i)
Next
If i <= 2 Then
Text2 = BytReceived(0)
BytReceived(0) = 0
Else
tongyi = BytReceived(0)
BytReceived(0) = 0
fandui = BytReceived(2)
BytReceived(2) = 0
qiquan = BytReceived(4)
BytReceived(4) = 0
End If
End Select