Check Digit Validation?

lizzieah

Registered User.
Local time
Today, 21:25
Joined
Mar 27, 2003
Messages
11
I have no clue how to do the following Check Digit Validation

Step 1- Add 1st and 5th Digit of a ID number, giving total of 1
Add 2nd and 4th Digit of a Id number, giving total of 2

Step 2- Add 3rd digit of Id Number to total 1 and total 2, giving total 3.

Step 3- While total 3 is greater than 9, add all the digits of total 3 together giving a new total 3. Repeat this unitl total 3 is single digit.

Step 4 - The Id number is valid when the 6th digit of the id number is same as toatl 3.

Confused? I am. Could be because im very new to the whole VB concept. Any help much appreciated
Thanks
 
I'm not going to write all the code for you and there are no guarentees because I'm not going to test it, but here's a start.

Public Function YourCheckSum(YourField As Long) As Boolean
Dim Sub1 As Long
Dim Sub2 As Long
Dim sub3 As Long
Dim Work3 As Long
Dim n As Int

Sub1 = Left(YourField,1) + Mid(YourField,5,1)
Sub2 = Mid(YourField,2,1) + Mid(YourField,4,1)
Sub3 = Sub1 + Sub2 + Mid(YourField,3,1)
Do Until Sub3 <10
n = Len(Sub3)
I'm too tired to work this out but you need to do the inner loop n times where n is the current length of Sub3 and at the end set the new value of Sub3 = Work3
Work3 = Mid(Sub3,n,1)

Loop
If Mid(YourField,6,1) = Sub3 Then
YourCheckSum = True
Else
YourCheckSum = False
End If
End Function
 
I don'tdispute the generality of Pat's approach, but a little maths can bring the task under control.

Total 1 and 2 are irrelevant as they just get totalled again. So the basis for the check digit is Digit 1+2+3+4+5

This has a maximum value of 45 (9+9+9+9+9)

The maximum value of the sum of the digits here is 12 (when the value is 39)

So there will only ever be a maximum of 2 iterations.

So the logic becomes
Work3 = Left(YourField,1) + Mid(YourField,2,1) + Mid(YourField,3,1) + Mid(YourField,4,1) + Mid(YourField,5,1)
Work3=IIF(Work3>9,Left(Work3,1)+Right(Work3,1),Work3)
 
Last edited:
Nice solution neileg. At 10:48 PM I'm not at my best and probably shouldn't have tried to code anything anyway. Wonder why lizzieah got such stupid directions? Your solution is so simple.
 
ok
it didnt work. it brings back the 1st and 5th number.

Eg- type in 123456
brings up 15

I dont know if i said but this is a assignment and he gave us examples of what should happen.

eg ID Number 123456
1+5=6, 2+4= 6
6+6+3=15
1+5= 6
6 is the same as the 6th digit, therefore valid id number

eg ID number 950178
9+7=16, 5+1=6
16+6+0=22
2+2=4
4 is not the same as the 6th digit, invalid id number

When it is invalid i also have to add the msg box that the id is invalid.
Im trying real hard to get it, its just not coming to me.
 
Sorry, I was trying to be too clever!

By using the string functions, left, mid and right, the number is converted to text. We need to convert it back. So try this:
Work3 = Left(YourField,1) + Mid(YourField,2,1) + Mid(YourField,3,1) + Mid(YourField,4,1) + Mid(YourField,5,1)
ChkDgt=IIF(Value(Work3)>9,Value(Left(Work3,1)+Right(Work3,1)), Value(Work3))
 

Users who are viewing this thread

Back
Top Bottom