我利用VB來做接受8051傳來的資料,因為要將資料分3次傳送,所以將程式寫成For迴圈的寫法,可是卻出現"陣列索引超出範圍"的訊息,請問我程式在何處出現錯誤呢?
Private Sub Command3_Click()
Dim InByte() As Byte
Dim Buf() As Byte
Dim TEST() As String
Dim i%, POS1$, POS2$
Again:
Text3.Text = ""
Text4.Text = ""
For j = 1 To 3
Do
If MSComm1.InBufferCount > 0 Then Exit Do
DoEvents
Loop
InByte = MSComm1.Input
For i = LBound(InByte) To UBound(InByte)
Buf(j) = Buf(j) + Str(InByte(i)) + Chr(13) + Chr(10)
Next i
POS1 = InStr(1, Buf(j), Chr(33)) + 1
POS2 = InStr(1, Buf(j), Chr(33)) + 5
TEST(j) = Mid(Buf(j), POS1 + 1, (POS2 - 1) - POS1)
Next j
If TEST2 = 1 Or TEST2 = 0 Then
Text4.Text = TEST2
Else
GoTo Again
End If
Text3.Text = (TEST * 256 + TEST1 + TEST2 * 128) * 3
If Text3.Text > 4000 Or TEST > 4 Then
GoTo Again
End If
End Sub

vbqa 發表在 痞客邦 留言(1) 人氣()