各位大佬
我在使用winsock控件时 通过getdata获取了一串字节流 保存在了ByteData数组中
当我将数据显示时 redata.Text=ByteData
就变成了乱码tcpclient.GetData ByteData, vbByte, bytesTotal
ByteLenght = bytesTotal
redata.Text=ByteData 时显示乱码
redata.Text=ByteData(Bytelenght-1)时显示的是字节流过来后的单个字节十进制数我想显示一串字节比如我接受到了一串字节流为
30 36 00 21 2F 61 31 49 47 39 5A 50 32 75 50 52 2F 6B 66 62 5F 64 65 6D 6F 2F 75 73 65 72 2F 73 5F 64 61 74 61 2D 31 38 2E 32 39 30 30 30 31 0A 32 2E 39 35 31 31 34 38 我想提取该字节流的后几个字节
32 2E 39 35 31 31 34 38 显示出来的应该是 2.951148当我使用
redata.Text=ByteData时是乱码
使用
redata.Text=ByteData(Bytelenght-1)时显示的是最后一个字节 38 对应的显示出来的是8
我在使用winsock控件时 通过getdata获取了一串字节流 保存在了ByteData数组中
当我将数据显示时 redata.Text=ByteData
就变成了乱码tcpclient.GetData ByteData, vbByte, bytesTotal
ByteLenght = bytesTotal
redata.Text=ByteData 时显示乱码
redata.Text=ByteData(Bytelenght-1)时显示的是字节流过来后的单个字节十进制数我想显示一串字节比如我接受到了一串字节流为
30 36 00 21 2F 61 31 49 47 39 5A 50 32 75 50 52 2F 6B 66 62 5F 64 65 6D 6F 2F 75 73 65 72 2F 73 5F 64 61 74 61 2D 31 38 2E 32 39 30 30 30 31 0A 32 2E 39 35 31 31 34 38 我想提取该字节流的后几个字节
32 2E 39 35 31 31 34 38 显示出来的应该是 2.951148当我使用
redata.Text=ByteData时是乱码
使用
redata.Text=ByteData(Bytelenght-1)时显示的是最后一个字节 38 对应的显示出来的是8
2. 最好可以检查一下发送数据和接收数据全部内容是否一致;
Dim arrByte(8) As Byte
arrByte(0) = &H32
arrByte(1) = &H2E
arrByte(2) = &H39
arrByte(3) = &H35
arrByte(4) = &H31
arrByte(5) = &H31
arrByte(6) = &H34
arrByte(7) = &H38
Dim strMsg As String
strMsg = StrConv(arrByte, vbUnicode)
MsgBox strMsg
End Sub运行示例:
十分感谢大佬的分享!
我现在把程序改成了这样子
Private Sub tcpclient_DataArrival(ByVal bytesTotal As Long)
ReDim ByteData(bytesTotal) tcpclient.GetData ByteData, vbByte, bytesTotal
ByteLenght = bytesTotal
Dim arrByte(8) As Byte
arrByte(0) = ByteData(ByteLenght - 8)
arrByte(1) = ByteData(ByteLenght - 7)
arrByte(2) = ByteData(ByteLenght - 6)
arrByte(3) = ByteData(ByteLenght - 5)
arrByte(4) = ByteData(ByteLenght - 4)
arrByte(5) = ByteData(ByteLenght - 3)
arrByte(6) = ByteData(ByteLenght - 2)
arrByte(7) = ByteData(ByteLenght - 1)
Dim strMsg As String
strMsg = StrConv(arrByte, vbUnicode)
redata.Text = strMsg
End Sub我运行时他提醒我下标越界 这个是怎么一回事鸭。。
我把光标放到bytesTOtal上时 它提醒我说bytesTotal=4
所以Bytelenght也就等于4了当我试着把强制改变bytelenght为一固定长度数组时还是提醒我下标越界