I have a database entry the is in a octal string. So it takes a text string and converts it into a hex.
Can someone post a code snipit to convert "test this 123" to hex and back?
Thanks
Printable View
I have a database entry the is in a octal string. So it takes a text string and converts it into a hex.
Can someone post a code snipit to convert "test this 123" to hex and back?
Thanks
Code:Private Sub Command1_Click()
x = "test this 123"
MsgBox "test this " & Hex(Right(x, 3))
MsgBox "test this " & CDbl(&H7B) 'hex uses &H before number
'oct uses &0
End Sub
I need to encode and decode the text string part too.
Well, it's beyond me....then again a lot of things are.
Hex Function:
Returns a String representing the hexadecimal value of a number.
Oct Fucntion:
Returns a Variant (String) representing the octal value of a number.
I need to encode and decode the text string part too.
Well
thanks for the lesson in hex....
Code:Private Sub Command1_Click()
Dim x As String, i As Integer, y As String
x = "test this 123"
For i = 1 To Len(x)
y = y & Hex(Asc(Mid(x, i, 1)))
Next i
MsgBox y
MsgBox UnHex(y)
End Sub
Public Function UnHex(sR As String) As String
Dim sTemp As String
Dim i As Integer, iKey As Integer
On Error Resume Next 'Trap for error
On Error GoTo 0 'Turn off error trapping
For i = 1 To Len(sR) Step 2 'Loop through each char in the given string
sTemp = sTemp & Chr$(Val("&H" & Mid$(sR, i, 2) & "&"))
Next i
UnHex = Trim$(sTemp) 'Return the string
End Function
That's what I needed. :)