How can I convert a hex value to a decimal value in VB6?
I'm trying just to see if this works:
Dim hexVal as string
hexVal = "#7B19AB"
clng("&H" & hexVal)
However, I'm getting "Type MisMatch" error.
To convert a hexadecimal string to a numberUse the ToInt32(String, Int32) method to convert the number expressed in base-16 to an integer. The first argument of the ToInt32(String, Int32) method is the string to convert. The second argument describes what base the number is expressed in; hexadecimal is base 16.
The VBA Hex Function Hexadecimals and Octals in VBA. If you want to refer to Hexadecimals or Octals directly in VBA, this can be done by preceding a hexadecimal with &H and an octal with &O. For example: &H10.
In order to convert a hex string into a normal string, the hex string has to be converted into a byte array, which is indexed and converted into smaller hex strings of two digits. The smaller hex strings are then concatenated into a normal string. For some values, a two digit hex string will start with a zero.
The VBA HEX function is listed under the data type conversion category of VBA functions. When you use it in a VBA code, it converts an expression into hexadecimal notation and returns the result as a string. Hexadecimal notation is just another base for representing numbers in, like binary.
Get rid of the # sign
Dim hexVal as string
hexVal = "7B19AB"
clng("&H" & hexVal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With