Need help with the current function:
I am working on generating a CheckDigit for a field.
The process is simple but yet iam not able to go around it, my head is not functioning at this point. Let me explain the process - If the Field is a name then, I am required to use the 3 weight-method using 7, 3, 1. The first char is multiplied with 7, then second char with 3, and third char with 1, the pattern is repeated till the last char. Then the sum of the product is divided by 10 to get a reminder. That reminder is the checkdigit.
Example:
Field hold "NIRAN"
Asc(N) * 7 = 78*7= 546
Asc(I) * 3 = 73*3= 219
Asc(R) * 1 = 82*1= 82
Asc(A) * 7 = 65*7= 455
Asc(N) * 3 = 78*3= 234
Total Product = 1546
CheckDigit = 1546 Mod 10 = 6
So I tried to Create a Public Function to be called:
Public Function DC(Strg As String)
Dim uStrg As String
Dim strLen As Integer
Dim tSum As Integer
Dim i, j, k As Integer
uStrg = ucase(Strg)
tSum = 0
For i = 1 To Len(uStrg)
tSum = tSum + (Asc(i) * 7)
For j = 1 To Len(uStrg) Step 2
tSum = tSum + (Asc(j) * 3)
For k = 1 To Len(Strg) Step 2
tSum = tSum + (Asc(k) * 1)
Next k
Next j
Next i
DC = tSum Mod 10
End Function
I am working on generating a CheckDigit for a field.
The process is simple but yet iam not able to go around it, my head is not functioning at this point. Let me explain the process - If the Field is a name then, I am required to use the 3 weight-method using 7, 3, 1. The first char is multiplied with 7, then second char with 3, and third char with 1, the pattern is repeated till the last char. Then the sum of the product is divided by 10 to get a reminder. That reminder is the checkdigit.
Example:
Field hold "NIRAN"
Asc(N) * 7 = 78*7= 546
Asc(I) * 3 = 73*3= 219
Asc(R) * 1 = 82*1= 82
Asc(A) * 7 = 65*7= 455
Asc(N) * 3 = 78*3= 234
Total Product = 1546
CheckDigit = 1546 Mod 10 = 6
So I tried to Create a Public Function to be called:
Public Function DC(Strg As String)
Dim uStrg As String
Dim strLen As Integer
Dim tSum As Integer
Dim i, j, k As Integer
uStrg = ucase(Strg)
tSum = 0
For i = 1 To Len(uStrg)
tSum = tSum + (Asc(i) * 7)
For j = 1 To Len(uStrg) Step 2
tSum = tSum + (Asc(j) * 3)
For k = 1 To Len(Strg) Step 2
tSum = tSum + (Asc(k) * 1)
Next k
Next j
Next i
DC = tSum Mod 10
End Function