Re: Winsock Hexadecimal Data
Why not use the following. Works for 1,2,4 byte numbers
Code:
Str = Right$("0000000" & Hex(timeGetTime), 8)
Re: Winsock Hexadecimal Data
Quote:
Originally Posted by
LaVolpe
Why not use the following. Works for 1,2,4 byte numbers
Code:
Str = Right$("0000000" & Hex(timeGetTime), 8)
That is fine.. But look at the code sample above. The Str variable contains string values which represent the timGetTime in String format which i can directly send via Winsock.Senddata. The code that you have given only displays in the Hex Number format. How do i convert into string? I will have to write it the other way around..
For Example if I need to send 1000 number in Hex data,
Hex(1000) = 3E8 and when we write it other way around its E8 03. Hence the Packet raw form is Winsock.Senddata chr(232) & chr(03). Its easier for a 2 byte value, but it gets complicated for a 6-8 byte value. Any suggestions?
Re: Winsock Hexadecimal Data
Code:
Str = Right$("0000000" & Hex(timeGetTime), 8)
Str = Chr$(Asc("&H" & Right$(Str, 2))) & _
Chr$(Asc("&H" & Mid$(Str, 5, 2))) & _
Chr$(Asc("&H" & Mid$(Str, 3, 2))) & _
Chr$(Asc("&H" & Left$(Str, 2)))
This may be a more generic algo for any byte structure. Note there is no standard variable type that is 6 bytes. 1, 2, 4, 8 is common.
Code:
' add CopyMemory to your declarations section
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
' here is a routine you may be able to use
Dim bData() As Byte, X As Long, Str As String
ReDim bData(1 To 4) ' change to nr bytes contained by variable
CopyMemory bData(1), variable, UBound(bData)
For X = 1 To UBound(bData)
Str = Str & Chr$(bData(X))
Next
Tweak as needed