Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert hex value to a decimal value in VB6

Tags:

vb6

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.

like image 423
webdad3 Avatar asked Jul 01 '11 22:07

webdad3


People also ask

How to convert hex value into integer?

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.

What is &H in VBA?

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.

How to convert hex to a string?

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.

Is hex a VBA?

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.


1 Answers

Get rid of the # sign

Dim hexVal as string
hexVal = "7B19AB"
clng("&H" & hexVal)
like image 193
JohnFx Avatar answered Sep 18 '22 20:09

JohnFx