Public Function BigMod(ByVal strNumber As String) As Long
'This function accepts as large integer as a string, and calculates
'the mod according to the given base. It then returns the remainder.
'Errors result in a return value of -1
'Declarations
Dim strSub As String
Dim i As Long
Dim lngCount As Long
Dim lngLoopCount As Long
Dim lngSubMod As Long
Dim lngModulo As Long
Dim boolError As Boolean
'Initialization
lngCount = Len(strNumber)
lngModulo = 97
boolError = False
'Checking for illegal characters in string
For i = 1 To lngCount
'Examine each character
strSub = Mid(strNumber, i, 1)
'If it's not a digit, set to error and exit loop
If Not strSub Like "#" Then
boolError = True
Exit For
End If
Next i
'If there was an error value, return -1 and exit the function
If boolError Then
BigMod = -1
Exit Function
End If
'Now, check to see if we even need this algorithm. We'll say
'if it's nine digits or less, we don't need to bother
If lngCount <= 9 Then
BigMod = CLng(strNumber) Mod lngModulo
Else
'Otherwise, let's see how many times we need to loop through this.
lngLoopCount = Application.WorksheetFunction.Ceiling((lngCount - 9) / 7, 1) + 1
'Do the first iteration of the loop
strSub = Left(strNumber, 9)
lngSubMod = CLng(strSub) Mod lngModulo
For i = 2 To lngLoopCount
'Take the ith 7 characters
strSub = Mid(strNumber, 3 + (i - 1) * 7, 7)
'Append the previous to the beginning
strSub = Format(lngSubMod, "00") & strSub
'Take the modulo of the result
lngSubMod = CLng(strSub) Mod lngModulo
Next i
'Once we've iterated all the way through, the last result
'is our answer
BigMod = lngSubMod
End If
End Function