第1个回答 2008-11-14
如果是你这种格式的数据,我有一个办法,不知道合不合你的意,:将这段数据存为一个文本文件,比如C:\text.txt 然后用下面的代码得到 D3 01 后面的数据
.
Private Sub Command1_Click()
Dim da As String, da1 As String
Open "C:\text.txt" For Input As #1
Do Until EOF(1)
Line Input #1, da
If Left(da, 5) = "D3 01" Then
da1 = Mid(da, 7, 2)
MsgBox da1 & " 就是你想要的数据"
Exit Do
End If
Loop
End Sub
第2个回答 2008-11-14
上面的改进版
Private Sub Command1_Click()
Dim da As String, da1 As String
dim tempstr as string
temp="D3 01"
Open "C:\text.txt" For Input As #1
Do Until EOF(1)
Line Input #1, da
If instr(da, temp)Then
da1 = Mid(da,instr(temp)+len(temp)+1 , 2) ‘这里的1是跳过1个空格
MsgBox da1 & " 就是你想要的数据"
Exit Do
End If
Loop
End Sub
这样不管你d3 01 在哪都能取后面的2位数据,设temp是方便你改数据
第3个回答 2008-11-14
Private Sub Command1_Click()
Dim AR() As String, AR2() As String
sTxt = "2 01 01 00 00 00 00 00 00 00 F4 44 0C 00 08 01 29 01 03 00 00 00 00 00 00 00 F4 44 0C 00 08 01 D3 01 04 00 00 00 00 00 00 00 F4 44 0C 00 08 01 2A 01 06 00 00 00 00 00 00 00 F4 44 0C 00 08 01"
AR = Split(sTxt, "D3 01")
L = LBound(AR) + 1
U = UBound(AR)
For i = L To U
tmp = Trim(AR(i))
AR2 = Split(tmp, " ")
'输出
Me.Print AR2(LBound(AR2)) & Space(2);
Next i
End Sub本回答被提问者采纳