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!

Check Digit Calculation

Status
Not open for further replies.

Muttley

MIS
Nov 22, 2000
50
US
Hi

I'm trying to write a routine that uses the Modulus 10 method to validate a number. I'm looking for some assistance with the code - has anyone done anything similar??

Any help much appreciated!

Mutt
 
For modulus calculations I use:

int(round(num1/num2,2))

I would love to see a more elegant solution if someone has it.


 
'This is a MOD 10 Add-Double-ADD routine.
Friend Function ComputeAddDoubleAddCheckDigit(strAcctNo As String) As String
Dim L As Integer, _
strResponse As String, _
intCk As Integer, I As Integer

L = Len(strAcctNo)
If Not (strAcctNo Like String(L, "#")) Or _
strAcctNo = String(L, "0") Then
strResponse = "X"
Else
Dim aryAddDouble As Variant
'* Sum of digits in number after doubling e.g. 2*9 = 18 1+8 = 9
aryAddDouble = Array(0, 2, 4, 6, 8, 1, 3, 5, 7, 9)

For I = 15 To 1 Step -2
intCk = intCk + aryAddDouble(CInt(Mid$(strAcctNo, I, 1)))
Next
For I = 14 To 2 Step -2
intCk = intCk + CInt(Mid$(strAcctNo, I, 1))
Next

intCk = (1000 - intCk) Mod 10
strResponse = CStr(intCk)
End If
ComputeAddDoubleAddCheckDigit = strResponse
End Function
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top