Board index » Visual Studio » Convext HEx value to byte array
|
thenextword
|
|
thenextword
|
Convext HEx value to byte array
Visual Studio50
Hi all , I have VB 6 application which request HEX value from hardware . I need to convert the HEX value to the byte array . Any ideas or suggestion how to do conversion ? The HEX VALUE is : 18 3E 16 00 00 00 00 00 Thanks - |
| Rick
Registered User |
Fri Oct 29 08:11:59 CDT 2004
Re:Convext HEx value to byte arrayQuoteI have VB 6 application which request HEX value from hardware . I one has answered you yet, here it goes. Function Hex2Byte(ByVal HexValue As String) As Byte() Dim X Dim ByteArray() As Byte HexValue = Replace(HexValue, " ", "") ReDim ByteArray((Len(HexValue) \ 2) - 1) For X = 0 To UBound(ByteArray) - 2 ByteArray(X) = CLng("&H" & Mid$(HexValue, 2 * X + 1, 2)) Next Hex2Byte = ByteArray End Function You can pass the HexValue in with the individual bytes separated by spaces or not. Hence, both of these function calls will return the same Byte array (using your example value). Hex2Byte("18 3E 16 00 00 00 00 00") Hex2Byte("183E160000000000") Rick - MVP - |
| Duane
Registered User |
Fri Oct 29 08:28:02 CDT 2004
Re:Convext HEx value to byte array
weetat wrote:
Quote
?val("&H"&"18" ) 24 - |
| Bob
Registered User |
Fri Oct 29 08:46:11 CDT 2004
Re:Convext HEx value to byte array
"weetat" <test@wavex-tech.com>wrote in message
QuoteHi all , Are those the byte values that you have read into a string? Are they just the byte values that you expect? Is this coming in over a COM port, LAN, USB, ??? Can you show the code that you are using to get the HEX VALUE? you haven't provided nearly enough information for anybody to provide a meaningful answer - |
| Larry
Registered User |
Fri Oct 29 15:57:22 CDT 2004
Re:Convext HEx value to byte array"Bob Butler" <tiredofit@nospam.com>wrote Quote>Any ideas or suggestion how to do conversion ? When will they learn? <g> LFS - |
| weetat
Registered User |
Mon Nov 01 03:32:41 CST 2004
Re:Convext HEx value to byte array
Hi Bob ,
Sorry for late reply 1 . Not including spaces 2 . Yes 3 . Yes 4 . COM port 5 . Sorry , cannot , using ActiveX DLL from our partner , confidential code Thanks Bob Butler wrote: Quote"weetat" <test@wavex-tech.com>wrote in message |
| Bob
Registered User |
Mon Nov 01 07:44:48 CST 2004
Re:Convext HEx value to byte array
"weetat" <test@wavex-tech.com>wrote in message
QuoteHi Bob , Reply to the group so all can participate VB.Net... just say "No" - |
| Bob
Registered User |
Mon Nov 01 07:49:33 CST 2004
Re:Convext HEx value to byte array
"weetat" <test@wavex-tech.com>wrote in message
QuoteHi Bob , 3 clear enough... If you have that sequence as a string in VB then I think you want something like this: Private Sub Main() Dim b() As Byte b = Hexify("183E10000000000") End Sub Public Function Hexify(ByVal TheBytes As String) As Byte() Dim b() As Byte Dim x As Long ReDim b(1 To Len(TheBytes) \ 2) For x = 1 To UBound(b) b(x) = CLng("&H" & Mid$(TheBytes, x * 2 - 1, 2)) Next Hexify = b End Function -- Reply to the group so all can participate VB.Net... just say "No" - |
| Rick
Registered User |
Mon Nov 01 08:31:49 CST 2004
Re:Convext HEx value to byte arrayQuotePublic Function Hexify(ByVal TheBytes As String) As Byte() Rick - |
| Bob
Registered User |
Mon Nov 01 09:13:20 CST 2004
Re:Convext HEx value to byte array
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message
Quote>Public Function Hexify(ByVal TheBytes As String) As Byte() -- Reply to the group so all can participate VB.Net... just say "No" - |
