下面的这段程序总是会在做红色标记的地方溢出,困惑我好久,不知为何。
Public V(SamNum + 1) As Long
Dim Num As Integer
Dim WTim As Integer
Dim ErrF As Boolean
Dim RecBuf() As Byte
Dim dat1(1000) As Byte
WTim = 0 '重发次数为0
resend:
If Form1.COM.PortOpen = True Then
Form1.COM.Output = "255" '发“传输数据的命令”给单片机
End If
ErrF = False
For TMP = 0 To 9 '延时,以保证单片机正确接受
Call Form1.delay
Next TMP
If Form1.COM.InBufferCount > 0 Then
RecBuf = Form1.COM.Input '取接收缓冲区数据
ElseIf Form1.COM.InBufferCount < 1 Then
Do While Form1.COM.InBufferCount < 1
delay = delay + 1
If (delay = 30000) Then
Form1.ComF.BackColor = RGB(255, 50, 125)
WTim = WTim + 1 '计重发次数
If (WTim < 100) Then
For TMP = 0 To 9
Call Form1.delay
Next TMP
GoTo resend:
Else: GoTo Err:
End If
End If
Loop
End If
Form1.Text2.Text = ""
For T = 0 To 127
dat1(T) = Trim(Str(RecBuf(T)))
Next T
For T = 0 To SamNum
V(T) = dat1(T * 2) * 256 + dat1(T * 2 + 1) '0-32极板的测量数据(当T=1,dat1(T * 2)=187,dat1(T * 2 + 1)=62时总是会溢出)
Next T