Hex - VBScript


The Hex command in VB Script converts an integer value to a hexadecimal string representation. It is commonly used for representing numeric values in a compact and human-readable format.


Function Hex(number)

| Parameter | Description |
| number | Required. The integer value to be converted. |




Dim myNumber = 123
Dim hexValue = Hex(myNumber) ' HexValue will be "7B"

To convert a negative number:

Dim myNumber = -123
Dim hexValue = Hex(myNumber) ' HexValue will be "FFFFFFFF85"

Common Issues

  • Invalid input: If the input number is not an integer or is outside the range of supported integer values, an error will occur.


The Hex command can be integrated with other VB Script commands to process and manipulate numeric data efficiently. For example, it can be used to convert hexadecimal strings back to integers using the Val function.

Dim hexValue = "7B"
Dim decimalValue = Val("&h" & hexValue) ' decimalValue will be 123
  • Dec – Converts a hexadecimal string to an integer.
  • Oct – Converts an integer to an octal string.
  • Val – Converts a string representation of a number to its numeric value.