'********************************************************************

'*

'* Function HexStr2Dec

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2004-12-05

'* Modified: 2006-06-09

'*

'* Purpose: Convert HEX String to a Decimal number.

'*

'*   Input: strHEX  A string of HEX Characters (0123456789ABCFEF)

'*

'*  Output: The decimal number equal to the HEX number represented.

'*

'*   Notes: Negative numbers are not supported.

'*

'********************************************************************

Function HexStr2Dec(ByVal strHEX)

  'Version: 1.3 2006-06-09

  Dim j, newNum, strNum, intTemp

 

  newNum = CDbl(0)

  strHEX = Trim(Ucase(strHEX))

  For j = 1 To Len(strHEX)

    strNum = Mid(strHEX, ((Len(strHEX) - j) + 1), 1)

    On Error Resume Next

    intTemp = CDbl("&H" & strNum)

    'Skip characters that are not valid HEX numbers.

    'Resulting in a "0" place holder value.

    'Example: 0x1Z1 = 0x101 = 257

    If Err.Number = 0 Then

      newNum = newNum + (intTemp * 16 ^ (j - 1))

    Else

      Err.Clear

    End If 'Err.Number <> 0

    On Error Goto 0

  Next 'j

  HexStr2Dec = newNum

End Function 'HexStr2Dec

Article ID: 396, Created On: 9/25/2011, Modified: 9/25/2011