How to convert Hex to Dec?

Alan,

In most cases, the following code will do the trick:

Dim s As String

Dim x As Long

s = "A"

x = CLng("&H" & s)

However, since VB uses signed Integers and Longs you can run into trouble with

the above depending on the source of the Hex value and/or its size. For

example, if you use the VB Hex finction to convert the Integer -1 into Hex you

get "FFFF". If you then convert this back using the above formula you will get

65535. The best way to avoid this to always use Longs.

Also if your Hex string comes from a system that uses unsigned integers/longs

you could get wrong answers.

Regards,

John.............

Quote:

> Hi Groups!

> I have a question converting a hexadecimal string to decimal value, so if we

> pass a "A" to that function, it will return "10" which is the decimal value

> for hex "A". Please help! thank you.