Function Any2Dec(ByVal ConvertNumber As String, Optional ByVal base As Integer = 16) As Long
Dim index As Long
Dim digits As String
Dim digitValue As Long
Rett = ConvertNumber
If base < 2 Or base > 36 Then Goto ByeBye ' Err.Raise 5 ' check base
digits = Left("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", base) ' get the list of valid digits
For index = 1 To Len(ConvertNumber) ' convert to decimal
digitValue = InStr(1, digits, Mid$(ConvertNumber, index, 1), vbTextCompare) - 1 ' get the digit's value
If digitValue < 0 Then Goto ByeBye ' Err.Raise 5 ' error if invalid digit
Rett = Rett * base + digitValue ' add to running result
Next
ByeBye:
Any2Dec = Rett
End Function
Dim index As Long
Dim digits As String
Dim digitValue As Long
Rett = ConvertNumber
If base < 2 Or base > 36 Then Goto ByeBye ' Err.Raise 5 ' check base
digits = Left("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", base) ' get the list of valid digits
For index = 1 To Len(ConvertNumber) ' convert to decimal
digitValue = InStr(1, digits, Mid$(ConvertNumber, index, 1), vbTextCompare) - 1 ' get the digit's value
If digitValue < 0 Then Goto ByeBye ' Err.Raise 5 ' error if invalid digit
Rett = Rett * base + digitValue ' add to running result
Next
ByeBye:
Any2Dec = Rett
End Function
ByVal ConvertNumber As String, Optional ByVal base As Integer = 16
Example Any2Dec("4F320D") =
Any2Dec("010001", 2) =
Any2Dec("012401", 5) =
Any2Dec("20180828", 10) = 20180828
Any2Dec("010001", 2) =
Any2Dec("012401", 5) =
Any2Dec("20180828", 10) = 20180828
Views 121
Downloads 59
CodeID
DB ID