是二进制的,是传感器发送来的。 Private Sub DP_PacketArrived(BaseStation As Byte, DataTag As Long, Value As String, Status As Byte, RSSI As Integer, CV As Integer, BattLow As Boolean, Error As Boolean) 'ensure that this is the one we want Debug.Print DataTag, Value, Status, RSSI, CV, BattLow, Error If (DataTag And 65535) <> (TestTag And 65535) Then Exit Sub Debug.Print DataTag, Value, Status, RSSI, CV, BattLow, Error 'put the value into the display label Label1.Caption = Value End Sub
Option Explicit Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long) Private Sub Form_Load() Dim value As String value = "asdafasdfasdfadfasdfaganbadfvgafgadsfasdfaefafgvafasdfaedfabadsfasdfaewfasgvabadfbadfgargarsrgfafasdfaewfasgvabadfbadfgargarsrgfa" Dim a() As Integer ReDim a(10 - 1) CopyMemory VarPtr(a(0)), StrPtr(value), LenB(a(0)) * (UBound(a) - LBound(a) + 1)
Dim i As Integer For i = LBound(a) To UBound(a) Debug.Print a(i) NextEnd Sub 你可以看懂么?
Dim Bytes() As Byte, i As Integer ReDim Bytes(3) For i = 0 To 3 Bytes(i) = 49 + i Next Debug.Print StrConv(Bytes(), vbUnicode) For i = LBound(Bytes) To UBound(Bytes) Debug.Print Chr(Bytes(i)) Next
如果是二进制格式的,转换成数组。
如果是定长的,用Mid函数。
Private Sub DP_PacketArrived(BaseStation As Byte, DataTag As Long, Value As String, Status As Byte, RSSI As Integer, CV As Integer, BattLow As Boolean, Error As Boolean)
'ensure that this is the one we want
Debug.Print DataTag, Value, Status, RSSI, CV, BattLow, Error
If (DataTag And 65535) <> (TestTag And 65535) Then Exit Sub
Debug.Print DataTag, Value, Status, RSSI, CV, BattLow, Error
'put the value into the display label
Label1.Caption = Value
End Sub
还有你能不能给我讲讲怎么得到这个Value的长度?我想看看和我VC中得到的长度是否一直。
你要贴出示例数据。
这个Value是什么样的。
LenB(Value) 二进制长度
51340 0+# 0+6 0+# 0+/ 0+/ 0+ 0+ 0+/ 0+/ 0+盱? 16 -45 48 False False
51340 0+# 0+ 0+ 0+ 0+ 0+ 0* 0+ 0+ 0+ 腚阚 16 -45 48 False False
51340 0+# 0+ 0+ 0+ 0+ 0+ 0* 0+ 0+ 0+ 腚阚 16 -45 48 False False
51340 0* 0+ 0+ 0+ 0+ 0+ 0+ 0+ 0+ 0+&黹| 16 -45 48 False False
51340 0* 0+ 0+ 0+ 0+ 0+ 0+ 0+ 0+ 0+&黹| 16 -45 48 False False
51340 0+/ 0+ 0* 0+ 0+# 0+# 0+ 0+ 0* 0+0黹鹄 16 -45 48 False False
51340 0+/ 0+ 0* 0+ 0+# 0+# 0+ 0+ 0* 0+0黹鹄 16 -45 48 False False
51340 0+ 0+ 0+ 0+ 0+ 0+/ 0+/ 0+/ 0+# 0+:黼fn 16 -45 48 False False
51340 0+ 0+ 0+ 0+ 0+ 0+/ 0+/ 0+/ 0+# 0+:黼fn 16 -45 48 False False
51340 0+ 0+ 0+ 0+ 0+) 0+6 0+) 0+ 0+ 0+D扃迆 16 -45 48 False False
51340 0+ 0+ 0+ 0+ 0+) 0+6 0+) 0+ 0+ 0+D扃迆 16 -45 48 False False
51340 0+ 0+ 0+ 0+/ 0+6 0+6 0+ 0+/ 0+# 0+N礻d 16 -45 48 False False
51340 0+ 0+ 0+ 0+/ 0+6 0+6 0+ 0+/ 0+# 0+N礻d 这些是调试的时候输出框输出的东西。可以帮我分析分析吗?
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
Private Sub Form_Load()
Dim value As String
value = "asdafasdfasdfadfasdfaganbadfvgafgadsfasdfaefafgvafasdfaedfabadsfasdfaewfasgvabadfbadfgargarsrgfafasdfaewfasgvabadfbadfgargarsrgfa" Dim a() As Integer
ReDim a(10 - 1)
CopyMemory VarPtr(a(0)), StrPtr(value), LenB(a(0)) * (UBound(a) - LBound(a) + 1)
Dim i As Integer
For i = LBound(a) To UBound(a)
Debug.Print a(i)
NextEnd Sub
你可以看懂么?
ReDim Bytes(3)
For i = 0 To 3
Bytes(i) = 49 + i
Next
Debug.Print StrConv(Bytes(), vbUnicode)
For i = LBound(Bytes) To UBound(Bytes)
Debug.Print Chr(Bytes(i))
Next
这句编译不过啊? 好像都没有CopyMemory VarPtr StrPtr这几个东西。能不能再帮帮忙看看怎么回事?
winhex查看,分析后确定分解方式。
不好意思,我没有注意看上面一段,只把下面的弄过来了。难怪不能用copymemory.谢谢了。