Convert Hex-String To Binary Data
Hello all,
I am trying to generate a DataMatrix-Barcode from data I get as a HEX-encoded binary string like this:
Data: 444541191C0025D6000000007F6501C70000300000000000000000000000000000000000000000000000009F554D75737465726D616E6E6F727400000000000000000000004D75737465726D616E6E737472617373650000000000313300000000000000004D6178204D75737465726D616E6E000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
I wrote a small function to transform this HEX-String to an ANSI-String:
dim hex
-
Nobody?
0 -
To work around this issue, change your script to:
For y = 1 To Len(hextext)num = Mid(hextext, y, 2)if num = "00" then num = vbNullres = res & Chr(CByte("&h" & num))y = y + 1Nextadding in the line "if num = "00" then num = vbNull" will convert the hex nul character to a vb based null character that the script editor can understand and pass into the barcode object.0 -
It works! Awesome :)
Thank you very much!
0 -
bringing that thread out of the cellar....
Above solution doesn't work because vbNull is represented as 0x01 (<SOH>) not 0x00 (<NUL>).
The "Deutsche Post" uses binary Datamtarix ECC200.so lets see what happens with above code:
if we have a hex data of "000000" eg. <NUL><NUL><NUL> this will be converted to vbNull&vbNull&vbNull.
and there's the failure: binary vbNull isn't 0x00 but 0x01.
So if we have a decimal value to be converted in its hex and then binary/string equivalent:
dec 100 -> hex 0064 -> string "<NUL>@" would be fine but the provided solution converts to
dec 100 -> hex 0164 -> string "<SOH>@" back to decimal this is dec 356 !!!!I really tried a lot to render binary data in Datamatrix with Bartender, but failed with even ADODB streams, arrays, Access-Databases. It always fails when it comes to 0x00.
Maybe anyone else has a solution for that.
Ralf Gebhard
0
Please sign in to leave a comment.
Comments
4 comments