Databases Reference
In-Depth Information
Function HexToLong(ByVal sHex As String) As Long
HexToLong = Val("&H" & sHex & "&")
End Function
G.5
VISUAL BASIC 3.0/ACCESS 2.0 AND EARLIER
The method illustrated above will not work in Microsoft Visual Basic 3.0 or earlier for
hexadecimal numbers greater or equal to 80000000. Please see the REFERENCES section of
this article for more information.
Because this problem does not occur with numbers that fall in the Integer Trap range, the alternate
function given below adds error trapping to try again without the appended “&” Long suffix:
Function HexToLong(ByVal sHex As String) As Long
On Error Resume Next
HexToLong = Val("&H" & sHex & "&")
If Err Then
On Error Goto 0
HexToLong = Val("&H" & sHex) End If
End Function
Usage of either version of the function is as follows:
A = HexToLong("8000")
REFERENCES
Microsoft Visual Basic Help topic: Va l Function
Microsoft Visual Basic 4.0 ReadMe topic: Coercion of Hexadecimal Values
For more information, please see the following article in the Microsoft Knowledge Base:
95431 (http://support.microsoft.com/kb/95431/EN-US/) FIX: Type Mismatch Error If Use VA L
Function on Big Value
G.6
APPLIES TO
• Microsoft Visual Basic 6.0 Learning Edition
• Microsoft Visual Basic 6.0 Professional Edition
• Microsoft Visual Basic 6.0 Enterprise Edition
• Microsoft Visual Basic 5.0 Control Creation Edition
• Microsoft Visual Basic 5.0 Learning Edition
• Microsoft Visual Basic 5.0 Professional Edition
• Microsoft Visual Basic 5.0 Enterprise Edition
• Microsoft Visual Basic 4.0 Standard Edition
• Microsoft Visual Basic 4.0 Professional Edition
• Microsoft Visual Basic 4.0 Enterprise Edition
• Microsoft Visual Basic 2.0 Standard Edition
• Microsoft Visual Basic 3.0 Professional Edition
• Microsoft Visual Basic 2.0 Professional Edition
• Microsoft Visual Basic 3.0 Professional Edition
Keywords:
kbhowto KB161304
&H8000 to &HFFFF Hex =
32,768 to
1, Affects LONG Bit Masking
Search WWH ::




Custom Search