View Full Version : Hex To Dec


rockies1
03-07-2002, 07:01 AM
I have a Hex value (will be like "FEFF4CD8") I need to convert to Decimal, but I do not know how...

Anyone have any pointers?

Thanks!

pcs
03-07-2002, 07:14 AM
from neatcode97...

Function Hex2Dec(strValue As String) As Long
On Error GoTo CnvrtErr
'
' Converts a string of hexadecimal digits into a decimal number.
' Valid input range '0' to '7FFFFFFF'
'
' Check to see if string already begins with &H.
If Left(strValue, 2) <> "&H" Then strValue = "&h" & strValue

' Check to see if string contains Decimals and strip them out.
If InStr(1, strValue, ".") Then strValue = Left(strValue, (InStr(1, strValue, ".") - 1))

Hex2Dec = CLng(strValue)
Exit Function

CnvrtErr:
Hex2Dec = 0

End Function

hth,
al