Visual Basic Language Reference  

Hex Function

Returns a string representing the hexadecimal value of a number.

Public Shared Function Hex( _
   ByVal Number As Byte | Short | Integer | Long | Object } _
) As String

Parameter

Number
Required. Any valid numeric expression or String expression.

Exceptions/Errors

Exception type Error number Condition
ArgumentNullException 5 Number is not specified.
ArgumentException 5 Number is not a numeric type.

Remarks

If Number is not already a whole number, it is rounded to the nearest whole number before being evaluated.

If Number is Hex returns
Empty Zero (0)
Any numeric value Up to sixteen hexadecimal characters

You can represent hexadecimal numbers directly by preceding numbers in the proper range with &H. For example, &H10 represents decimal 16 in hexadecimal notation.

Example

This example uses the Hex function to return the hexadecimal value of a number.

Dim MyHex As String
MyHex = Hex(5)   ' Returns 5.
MyHex = Hex(10)   ' Returns A.
MyHex = Hex(459)   ' Returns 1CB.

See Also

Oct Function | Type Conversion Functions | ArgumentNullException