Public Function CheckSum(gstin As String) As String
Dim symbList(0 To 35) As String * 1
Dim gstinList(0 To 13) As String * 1
Dim symbs As String
Dim gstin14 As String
Dim checkDigit As String
Dim newCheckDigit As String
Dim i As Integer, j As Integer
checkDigit = Right(UCase(gstin), 1)
gstin14 = Left(UCase(gstin), 14)
For i = 0 To 13
gstinList(i) = Mid(gstin14, i + 1, 1)
Next
symbs = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
For i = 0 To Len(symbs) - 1
symbList(i) = Mid(symbs, i + 1, 1)
Next
Dim factor As Integer
Dim sum As Integer
Dim checkCodePoint As Integer
Dim mode As Integer
factor = 2: sum = 0: mode = Len(symbs)
For i = UBound(gstinList) To 0 Step -1
Dim codePoint As Integer, digit As Integer
codePoint = -1
For j = 0 To UBound(symbList)
If symbList(j) = gstinList(i) Then
codePoint = j
End If
Next
digit = factor * codePoint
factor = IIf(factor = 2, 1, 2)
digit = (digit \ mode) + (digit Mod mode)
sum = sum + digit
Next
checkCodePoint = (mode - (sum Mod mode)) Mod mode
CheckSum = symbList(checkCodePoint)
End Function