Hex, Hex$ Functions

See Also84KIPK              ExampleGU5XLM>Low

Returns a string that represents the hexadecimal value of a decimal argument.

Syntax

Hex[$](number)

Remarks

Hex returns a Variant8PHEAW3; Hex$ returns a String.

The argument number can be any numeric expression71RISN.  It is rounded to the nearest whole number before being evaluated.  An error occurs if number is a Variant of VarType7A68ZTZ 1 (Null1DDW7C0).

If the argument is an Integer or a Variant of VarType 2 (Integer) or VarType 0 (Empty1L2JEZ4), up to four hexadecimal characters are returned; if the argument is any other numeric data type, or a Variant of any other type, up to eight hexadecimal characters are returned.

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


See Also

Oct, Oct$ FunctionLANOCT


Hex, Hex$ Function Example

The example uses Hex to return the hexadecimal representation of a decimal number.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim Msg, Num                          ' Declare variables.

   Num = InputBox("Enter a number.")     ' Get user input.

   Msg = Num & " decimal is &H"

   Msg = Msg & Hex(Num) & " in hexadecimal notation."

   MsgBox Msg                            ' Display results.

End Sub