通信中的循环语句?
Option ExplicitDim ary() As String
Dim buf As Variant
Dim buf1 As Variant
Dim i As Integer '变量的声名
Private Sub Form_Load()
= 2
MSC.Settings = "1200,n,8,1"
MSC.InBufferCount = 0
MSC.InputLen = 9
MSC.RThreshold = 9
MSC.PortOpen = True
End Sub 'mscomm的初始化
Private Sub Form_Unload(Cancel As Integer)
If MSC.PortOpen = True Then MSC.PortOpen = False
End Sub
Private Sub MSC_OnComm()
Select Case
Case comEvReceive
buf = MSC.Input
ReDim ary(Len(buf) - 1)
For i = 1 To Len(buf)
ary(i - 1) = Mid(buf, i, 1)
Next
Do While ary(0) <> "="
txtreceive.Text = " "
buf = MSC.Input
ReDim ary(Len(buf) - 1)
For i = 1 To Len(buf)
ary(i - 1) = Mid(buf, i, 1)
Next
Loop '判断第一个字节是否为“=”,不是就进行循环等待!
For i = 0 To UBound(ary)
buf1 = buf1 + ary(i)
Next
txtreceive.Text = buf1
buf1 = ""
Case comEvSend
End Select
End Sub
如果msc.input字符串中的第一个字符为“=”号,就能运行成功!如果不是,我就用do while 语句进行循环等待,我运行了多次发现,如果第一个字符不是“=”时,就运行错误,
错误提示是:实时错误“9”,下标越界。 真的不知哪儿错了?请高手帮忙看看!