错误有几个:
1, Text1.Text = MSComm1.input 写到End Select后面
2, 不定长数据的接收用UBound函数截取长度
3,给你一个 例子,是接受3组信号的,分别为温度,深度,速度
On Error Resume Next
Dim i&, sum, SS, dd, vv, Xx, Yy, ww
Dim lk As Long
Dim an As Integer
Dim nn As Integer
Dim Buffer As Variant
Select Case MSComm1.CommEvent
Case comEvReceive
Buffer = MSComm1.Input
a = Len(Buffer)
If a <= 2 Then
rc = InStr(Buffer, "Y")
If rc <> 1 Then
MSComm1.Output = Chr("88") '& Chr("33")
ElseIf rc = 1 Then
MSComm1.InputLen = 0
RightCom = MSComm1.CommPort
Form9.Show '显示连接成功
End If
Else
For lk = 0 To UBound(Buffer)
data = data & Buffer
Next lk
an = Len(data)
SS = InStr(data, "T")
dd = InStr(data, "H")
vv = InStr(data, "V")
If vv = 0 Then
x0 = 0
y0 = Picture1.Height
x1 = 0
y1 = Picture1.Height
x2 = 0
y2 = Picture1.Height
Exit Sub
End If
ww = Mid(data, SS + 1, dd - SS - 1)
Xx = Mid(data, dd + 1, vv - dd - 1)
Yy = Mid(data, vv + 1, an - vv)