HexToDec



Private Function HextoDec(HexNum As String) As Long
'converts a hexadecimal value to a decimal value

'You can use the characters a-f but also A-F (in capitals)

'for example: label1.caption = HextoDec("Ab789Ff")

'returns as the labels caption: 179800575

'an error handling is included

Dim xx%, yy%

For xx = 1 To Len(HexNum)
If Asc(Mid(HexNum, xx, 1)) < 48 Then Goto HexError
If Asc(Mid(HexNum, xx, 1)) > 57 And Asc(Mid(HexNum, _
xx, 1)) < 65 Then Goto HexError
If Asc(Mid(HexNum, xx, 1)) > 70 And Asc(Mid(HexNum, _
xx, 1)) < 97 Then Goto HexError
If Asc(Mid(HexNum, xx, 1)) > 102 Then Goto HexError
Next xx

HextoDec = "&h" & HexNum
Exit Function
HexError:
hextodectemp = MsgBox(UCase(HexNum) & _
" is not a valid hexadecimal number", _
vbOKOnly + vbCritical, "Hex_to_Dec")
End Function

(hextodec.html)- by Paolo Puglisi - Modifica del 25/3/2019