23 lines
621 B
Plaintext
23 lines
621 B
Plaintext
|
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
|