7,765
社区成员
发帖
与我相关
我的任务
分享
Private Sub MSComm2_OnComm()
Dim t1 As Long, com_String As String
Static i As Integer
t1 = Timer
Sleep 100
Select Case MSComm2.CommEvent
Case comEvReceive '收到 RThreshold定义的字符数1字节
MSComm2.RThreshold = 0
Do
DoEvents
Loop While Timer - t1 < 0.6 '延时时间
com_String = MSComm2.Input
MSComm2.RThreshold = 1
i = i + 1: If i > 255 Then i = 1
Cells(actiCell + 1, actiColumn) = com_String
' Cells(actiCell + 1, 0).Value = com_String
'Selection.Offset(0, 1).Select
'Application .Cells(3, i).Value = com_String
End Select
'ActiveWorkbook.SaveAs Filename:="C:\d1.xls"
End Sub
'模拟一次测试数据'
com_String = "0 MW +0039.754 mm"
'下面是提取方式'
Dim a() As String
a = Split(com_String, " ")
If UBound(a) >= 2 Then
Debug.Print "长度=" & a(2)
End If
长度=+0039.754