Home > Software engineering >  VB in receiving display garbled byte streams
VB in receiving display garbled byte streams

Time:11-14

,
I when using winsock control through getdata access to a string of bytes stored in the ByteData array
When I will be according to redata. Text ByteData=
Become garbled

Tcpclient. GetData ByteData vbByte, bytesTotal
ByteLenght=bytesTotal
Redata. Text=ByteData displayed when the code
Redata. Text=ByteData (Bytelenght - 1) is displayed when the byte stream over a single byte after the decimal number

I want to show that a string of bytes

Such as I have received a string of bytes for the
30 36 00 21 2 f 61 49 47 39 5 a 50 31 32 75 50 52 2 f 6 b, 66, 62 5 64 65 6 d f, 2 f, 75 f, 73, 65, 72, 2 f, 73 f, 64, 61, 74 61 31 38 2 e 2 d 32 39 30 30 30 31 0 a 2 e 39 35 and 31 34 38

I want to extract the byte stream after several bytes
35 and 31 32 2 e 39 34 38 display should be 2.951148

When I use
Redata. Text is stil ByteData=
Use the
Redata. Text=ByteData (Bytelenght - 1) is displayed when the last byte 38 corresponding display is 8



CodePudding user response:

1. Can be done with strconv byte array and the transformation of the string;
2. Best can check the data sending and receiving data all contents are consistent;

CodePudding user response:

reference 1st floor milaoshu1020 response:
1. Can be implemented with strconv byte array and the transformation of the string;
2. Best can check the data sending and receiving data all contents are consistent;


Bosses can express the
I receive data part in addition to the above the line no other code

CodePudding user response:

Give you wrote a simple transformation methods:
 
Option Explicit

Private Sub Form_Load ()
Dim arrByte As Byte (8)
ArrByte (0)=& amp; H32
ArrByte (1)=& amp; H2E
ArrByte (2)=& amp; H39
ArrByte (3)=& amp; H35
ArrByte (4)=& amp; H31
ArrByte (5)=& amp; H31
ArrByte (6)=& amp; H34
ArrByte (7)=& amp; H38

Dim strMsg As String
StrMsg=StrConv (arrByte vbUnicode)

MsgBox strMsg
End Sub

Run the example:

CodePudding user response:

reference milaoshu1020 reply: 3/f
give you wrote a simple transformation methods:
 
Option Explicit

Private Sub Form_Load ()
Dim arrByte As Byte (8)
ArrByte (0)=& amp; H32
ArrByte (1)=& amp; H2E
ArrByte (2)=& amp; H39
ArrByte (3)=& amp; H35
ArrByte (4)=& amp; H31
ArrByte (5)=& amp; H31
ArrByte (6)=& amp; H34
ArrByte (7)=& amp; H38

Dim strMsg As String
StrMsg=StrConv (arrByte vbUnicode)

MsgBox strMsg
End Sub

Run the example:


Thank you very much bosses share!
I now changed to a program like this
Private Sub tcpclient_DataArrival (ByVal bytesTotal As Long)
ReDim ByteData (bytesTotal)

Tcpclient. GetData ByteData vbByte, bytesTotal
ByteLenght=bytesTotal

Dim arrByte As Byte (8)
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

He reminds me of when I run the subscript crossing this is how one and the same duck,,
It reminds me of when I put the cursor on the bytesTOtal said bytesTOtal=4
So Bytelenght also equals 4

When I try to change the mandatory bytelenght as a fixed or call me when the length of the array subscript crossing the line


CodePudding user response:

CodePudding user response:

1. Can use cycle;
2. The data may be less than 8 bytes;
  • Related