Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modulus 11 Coding

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0

Hello

I'm new to VBA coding. I'm involved in a project where I have to add Modulus11 checkdigits to an OCR codeline for Invoicing. I got my hands on the code for the Mod 11 checkdigit producer in Ordinary BASIC. It's as follows -

Sub anpostocr(Checkdigit$)
'--checkdigit$ = Command$

Dim checkarray(40)
Dim weight(40)

lent = Len(Checkdigit$) '--get lenght of string

For i = 0 To (lent - 1) '--split up string digit by digit & put in array
checkarray(i + 2) = Val(Mid$(Checkdigit$, (lent - i), 1))
Next i

For i = 2 To lent + 1 '--calculate the weights for each digit
weight(i) = (checkarray(i) * i)
sum = sum + weight(i)
Next i
'--sum now holds value we need
Checkdigit = 11 - (sum Mod 11)
If Checkdigit >= 10 Then Checkdigit = Checkdigit - 10 '---for case of 10 or 11
checkarray(1) = Checkdigit '--add the checkdigit to the

'-- for debug only-- PRINT " CheckDigit is > "; checkdigit

For i = (lent + 1) To 1 Step -1 '--go through the array backwards & rebuild string with check digit attached
checkout$ = checkout$ + LTrim$(Str$(checkarray(i)))
Next i

Checkdigit$ = checkout$
'--Print checkout$
End Sub

I copied it to a new module in access XP. Do I need to make changes to it in order for it to run? I would like it to run in one of two ways.

1) The checkdigits to be output on a Access report and the module to take input from both queries and the report itself.

2) The Checkdigits to be included in a query to be read from Crystal reports where the Invoice could be produced

Any help on how I could implement this would be much appreciated.

Paraic
 

Thanks

There certainly is alot of information on that site

Paraic
 
Hmmmmmmmmmmmmm ---
Well, the posted sub will (with very minor changes) work in VBA. I re-coded it to be a LITTLE less arcane, as below, just to be able to (somewhat) more easily read it and compare to a different use application to Mod 11 implementation. It turns out that they are totally different, but I thought this might be easier to follow.


Code:
Public Function basMod11Chk(ChkChr As String) As String

    'Michael Red    3/21/2002   Adapted from Tek-Tips thread

    Dim Idx As Integer
    Dim ChkSum As Long
    Dim ChkVal As Integer
    Dim Wgt As Long
    Dim MyStr As String
    Dim MyChr As String

    If (Not IsNumeric(ChkChr)) Then
        Exit Function
    End If

    For Idx = Len(ChkChr) To 1 Step -1     'One Char at a time - BACKWARDS
        MyChr = Mid$(ChkChr, Idx, 1)
        Wgt = Val(MyChr) * (Len(ChkChr) - Idx + 2)
        ChkSum = ChkSum + Wgt
    Next Idx

    ChkVal = (11 - (ChkSum Mod 11))

    If (ChkVal >= 10) Then
        ChkVal = ChkVal - 10 '---for case of 10 or 11
    End If

    basMod11Chk = ChkChr & Trim(str(ChkVal))

End Function
[code]


 MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top