|
-
Sep 19th, 2000, 02:31 PM
#1
Thread Starter
Hyperactive Member
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!?
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
Any suggestions?
thx, vbzero
-
Sep 19th, 2000, 02:56 PM
#2
Monday Morning Lunatic
In decHex - use Split() rather than the loop to extract each individual part. Either that, or loop through, checking for spaces.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 19th, 2000, 03:24 PM
#3
Thread Starter
Hyperactive Member
Can you please show me that in code?
thx, vbzero
-
Sep 19th, 2000, 03:43 PM
#4
Monday Morning Lunatic
Code:
Private Function encHex(sValue As String) As String
On Error Resume Next
Dim i As Integer
For i = 1 To Len(sValue)
encHex = encHex + Hex(Asc(Mid(sValue, i, 1))) + " "
Next i
encHex = Trim(encHex)
End Function
Private Function decHex(sValue As String) As String
On Error Resume Next
Dim sTemp As String
Dim sCh As String
Dim i As Integer
For i = 1 To Len(sValue)
sCh = Mid(sValue, i, 1)
If sCh = " " Then
decHex = decHex + Chr(CInt(Val("&h" + sTemp)))
sTemp = ""
Else
sTemp = sTemp + sCh
End If
Next i
decHex = decHex + Chr(CInt(Val("&h" + sTemp)))
End Function
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 20th, 2000, 05:56 PM
#5
Thread Starter
Hyperactive Member
Thank you very much! This problem is solved!
thx, vbzero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|