I use those functions to encode and decode a string to hex.
There is a problem - maybe a little bug - when I encode
a string 1f;1 then a hex number 12 31 66 3B 2 1F 2 31 will be generated.
When I decode 12 31 66 3B 2 1F 2 31 then a string 1f;
will be generated. The function decodes a instead of 1 in
the string.
I can't find that nasty bug! - Can anyone help me, please!?
Any suggestions?Code:Public Function encHex(strValue As String) As String On Error Resume Next Dim i As Integer For i = 1 To Len(strValue) encHex = encHex + Hex(Asc(Mid(strValue, i, 1))) If (Len(encHex) Mod 2) = 0 Or (Len(encHex) - 1 Mod 2) Then encHex = encHex + " " End If Next i encHex = Trim(encHex) End Function Public Function decHex(strValue As String) As String On Error Resume Next Dim sTemp As String sTemp = strValue + " " Dim i As Integer For i = 1 To Len(sTemp) Step 3 decHex = decHex + Chr(CLng(Val("&h" + Mid(sTemp, i, 2)))) Next i End Function
thx, vbzero




Reply With Quote