主题:[原创]看看这段代码?
Option Explicit
Dim ary() As Byte
Dim buf As Variant
Dim buf1 As Variant
Dim i As Integer
Private Sub Form_Load()
MSC.CommPort = 2
MSC.Settings = "1200,n,8,1"
MSC.InBufferCount = 0
MSC.InputLen = 9
MSC.RThreshold = 9
MSC.PortOpen = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSC.PortOpen = True Then MSC.PortOpen = False
End Sub
Private Sub MSC_OnComm()
Select Case MSC.CommEvent
Case comEvReceive
buf = MSC.Input
ary = StrConv(buf, vbFromUnicode)
For i = 0 To UBound(ary)
[color=FF00FF]Do While Chr(ary(0)) <> "="
txtreceive.Text = ""
Loop[/color]
buf1 = buf1 + Chr(ary(i))
Next
txtreceive.Text = buf1
buf1 = ""
Case comEvSend
End Select
End Sub
不知怎么了这段代码一运行就死机!msc.input是仪表传送过来的数据,(比如仪表传数据为
=11.52000=11.52000=11.52000...),别的语句没问题!就是do while语句?
Dim ary() As Byte
Dim buf As Variant
Dim buf1 As Variant
Dim i As Integer
Private Sub Form_Load()
MSC.CommPort = 2
MSC.Settings = "1200,n,8,1"
MSC.InBufferCount = 0
MSC.InputLen = 9
MSC.RThreshold = 9
MSC.PortOpen = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSC.PortOpen = True Then MSC.PortOpen = False
End Sub
Private Sub MSC_OnComm()
Select Case MSC.CommEvent
Case comEvReceive
buf = MSC.Input
ary = StrConv(buf, vbFromUnicode)
For i = 0 To UBound(ary)
[color=FF00FF]Do While Chr(ary(0)) <> "="
txtreceive.Text = ""
Loop[/color]
buf1 = buf1 + Chr(ary(i))
Next
txtreceive.Text = buf1
buf1 = ""
Case comEvSend
End Select
End Sub
不知怎么了这段代码一运行就死机!msc.input是仪表传送过来的数据,(比如仪表传数据为
=11.52000=11.52000=11.52000...),别的语句没问题!就是do while语句?