The MOD-37 barcode function is used in some IDAutomation Barcode Products to create an ISBT-128 compatible check character K according to the ISO 7064 MOD 37-2 Algorithm. IDAutomation also provides MOD-37 VB source code for this calculation and a Crystal Reports Barcode Tutorial.
The VBA source code below for the function may also be easily translated into other programming languages as necessary.
Public Function ISO_MOD37_2(DataString As String, Optional ReturnType As Integer = 0) As String DataString = UCase(DataString) Dim CorrectData As String Dim WeightedSum As Long Dim StringLength As Long Dim AscValue As Long Dim CharValue As Long Dim CheckDigitAscVal As Long Dim CheckDigitAsc As Long Dim StringLen As Long Dim I As Long StringLen = Len(DataString) For I = 1 To StringLen AscValue = AscW(Mid(DataString, I, 1)) If AscValue < 58 And AscValue > 47 Then CorrectData = CorrectData & Mid(DataString, I, 1) '0-9 If AscValue < 91 And AscValue > 64 Then CorrectData = CorrectData & Mid(DataString, I, 1) 'A-Z Next I DataString = CorrectData CorrectData = "" WeightedSum = 0 StringLength = Len(DataString) For I = 1 To StringLength AscValue = AscW(Mid(DataString, I, 1)) If AscValue < 58 And AscValue > 47 Then CharValue = AscValue - 48 '0-9 = values 0-9 If AscValue < 91 And AscValue > 64 Then CharValue = AscValue - 55 'A-Z = values 10-35 WeightedSum = ((WeightedSum + CharValue) * 2) Mod 37 Next I CheckDigitAscVal = (38 - WeightedSum) Mod 37 If CheckDigitAscVal < 10 Then CheckDigitAsc = CheckDigitAscVal + 48 '0-9 If CheckDigitAscVal < 36 And CheckDigitAscVal > 9 Then CheckDigitAsc = CheckDigitAscVal + 55 'A-Z If CheckDigitAscVal = 36 Then CheckDigitAsc = 42 '* If ReturnType = 1 Then ISO_MOD37_2 = " [" & ChrW(CheckDigitAsc) & "]" If ReturnType = 0 Then ISO_MOD37_2 = ChrW(CheckDigitAsc) End Function