Public Function AnyToDecimal(ByVal InputStr As String, ByVal InBase As Integer) As Long
     'Input  - InputStr - Any number in any base as string representation	    
     '       - InBase   - The input number base must be in the range 2 - 36
     '
     'Output - Converted decimal value.
     '       - -1 if wrong input base or error encountered
     '
     On Error GoTo ErrHndl
      
     Dim TestChar As Char
     Dim TestPlace As Long
     Dim i As Integer

     If InBase <2 Or InBase > 36 Then
         'InBase must be in the range 2 - 36, so return -1
         AnyToDecimal = -1
         Exit Function
     End If
     
     'All character bases up to 36
     Const CharSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

     For i = Len(InputStr) To 1 Step -1
         'Test one character at a time
	 TestChar = Mid$(InputStr, i, 1)

         TestPlace = InStr(1, CharSet, TestChar, vbTextCompare) - 1

	 If TestPlace < 0 Or TestPlace > InBase Then
             'Checks if the character is a valid one, if not valid then return -1
             AnyToDecimal = -1
             Exit Function
	 End If

         AnyToDecimal = AnyToDecimal + TestPlace * InBase ^ (Len(InputStr) - i)
     Next i

     Exit Function

 ErrHndl:
     'Error handling - return Null string
     AnyToDecimal = -1
		
 End Function