Any2Dec




Function Any2Dec(ByVal otherBaseNumber As String, ByVal base As Integer) As Long
Dim index As Long
Dim digits As String
Dim digitValue As Long

' check base

If base < 2 Or base > 36 Then Err.Raise 5
' get the list of valid digits

digits = Left("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", base)

' convert to decimal

For index = 1 To Len(otherBaseNumber)
' get the digit's value

digitValue = InStr(1, digits, Mid$(otherBaseNumber, index, 1), _
vbTextCompare) - 1
' error if invalid digit

If digitValue < 0 Then Err.Raise 5
' add to running result

Any2Dec = Any2Dec * base + digitValue
Next

End Function










( any2dec.html )- by Paolo Puglisi - Modifica del 17/12/2023