Name
Hex Function
Syntax
Hex(number)-
number Use: Required
Data Subtype: Numeric or String
A valid numeric or string expression.
Return Value
String representing the hexadecimal value of
number.
Description
Returns a string that represents the hexadecimal value of a number.
Rules at a Glance
If
numbercontains a fractional part, it’s rounded automatically to the nearest whole number prior to processing.numbermust evaluate to a numeric expression that ranges from -2,147,483,648 to 2,147,483,647. If the argument is outside this range, runtime error 6, “Overflow,” results.The return value of
Hexis dependent upon the value and type ofnumber:
|
number |
Return Value |
|---|---|
|
Null |
Null |
|
Empty |
Zero (0) |
|
Any other number |
Up to eight hexadecimal characters |
Programming Tips & Gotchas
If the value of number is known beforehand
and isn’t the result of an expression, you can represent the
number as a hexadecimal by simply affixing &H
to number. Each of the following
statements assigns a hexadecimal value to a variable:
lngHexValue1 = &HFF ' Assigns 255 lngHexValue2 = "&H" & Len(dblNumber) ' Assigns 8
VBA/VBScript Differences
The Hex$ function, which returns a string (as
opposed to variant string) datatype, is not available in VBScript.
See Also
| Oct Function |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access