How can I transform a hexadecimal string in a textbox to a long?
Printable View
How can I transform a hexadecimal string in a textbox to a long?
When I now use a letter in the textbox (A to F), I get an error type mismatch.
What can I try else?
Here is one way:
Of course this assumes that the value doesn't have the "&H" before it and the "&" after it. If the value in the text box already has these VB pre- and post-fixes to the number, then you can just do this:Code:Function HexToLong(ByVal sHex As String) As Long
HexToLong = Val("&H" & sHex & "&")
End Function
Here's an article about this on MSDN (a most valuable resource).Code:MyLong = Val(Text1.Text)
Hope that helps!