How to calculate a checksum by modulus 10

H

Hallgeir

Is there an easy way to calculate the last checksum digit in a number in
accordance to modulus 10.
From the query I have for instance a number 010394011824, I want this to
print as 0103940118245 in my report. If it's easier I could just as well
calculate it in the query, but my problem is that it gets a bit to
complicated for me. Is there a common control or simular that I can use? I
appreciate any suggestions.
 
S

Stefan Hoffmann

hi,
Is there an easy way to calculate the last checksum digit in a number in
accordance to modulus 10.
From the query I have for instance a number 010394011824, I want this to
print as 0103940118245 in my report. If it's easier I could just as well
calculate it in the query, but my problem is that it gets a bit to
complicated for me. Is there a common control or simular that I can use? I
appreciate any suggestions.
You can use CStr([NumberField]) & CStr([NumberField] % 10) in your query
(formula AS fieldname) or on your report (=formula).


mfG
--> stefan <--
 
M

Marshall Barton

Hallgeir said:
Is there an easy way to calculate the last checksum digit in a number in
accordance to modulus 10.
From the query I have for instance a number 010394011824, I want this to
print as 0103940118245 in my report. If it's easier I could just as well
calculate it in the query, but my problem is that it gets a bit to
complicated for me. Is there a common control or simular that I can use? I
appreciate any suggestions.


Here's a little function that does one kind of check sum
(but it gets 3 instead of 5).

Function CheckSum(num As Variant) As Variant
Dim strNum As String, K As Integer

If Len(num & vbNullString) Then
strNum = CStr(num)
If Not strNum Like "*[!0-9]*" Then
CheckSum = 0
For K = 1 To Len(strNum)
CheckSum = CheckSum + CInt(Mid(strNum,K,1))
Next K
CheckSum = CheckSum Mod 10
End If
End If
End Function

If your idea of a check sum includes the number of digits,
then change the line CheckSum = 0 to
CheckSum = Len(strNum)

If you used a modulus 9 check sum, the the entire inner If
block would be just: CheckSum = num Mod 9

Your report text box can then use an expression like:
=numfield & CheckSum(numfield)
 
S

Stefan Hoffmann

hi Klatuu,
That will not do it.
That is may be true, as i don't know the common checksum algorithm used
in the States.
The Check Digit Modulus 10 calculation is a specific algorithm used to
determine the accuracy of a numeric string. It is used to validate things
like bank account or credit card numbers.
I have done them once for money cards in Germany. There are a lot of
different algorithms: e.g. ISBN.

But i wasn't clear for me that the OP wanted a special algorithm.

Wish you a Merry Christmas.

mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top