Numeric Transposition Prevention

Does anyone know an algorithm or set of rules that can be used to generate numbers that are resistant to transposition errors?
LVL 1
chaos_59Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AllenC_JrCommented:
If you could Re-formulate your question, and Give a more specific example of your dilema.  I am very sure that a Response will be available sooner than later.

Regards,
Allen
0
brandonbCommented:
An easy way to prevent transposition is to use check digit routines.  Two of the most common routines are mod 10 and mod 11.  Basically, each digit is weighted.  The digits are multiplied by the weight and added together.  The result must be evenly divisible by 10 or 11.  Take the mod 11 number 176303 for example:

number:  1 7 6 3 0 3
weights: 6 5 4 3 2 1

(1*6)+(7*5)+(6*4)+(3*3)+(0*2)+(3*1)=77
77/11=7

Since the 7 is an integer, the number is valid.  The weights can be whatever you want them to be.

I don't have an algorithm in VB to create the check digit, but basically you take the left 5 digits (in this case) and start with the right most digit being 0.  Check it for validity.  If it fails, add 1 to the whole number.  Check again.  Eventually you will find a valid number.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
deightonprogCommented:

'for seven digit account numbers e.g "0000000" and so on


Public Function NextAccount(x As String) As String
   
    Dim y As String
   
    y = x
   
    Do
   
        y = Format(y + 1, "0000000")
       
    Loop Until CheckDigit(y) = 9

    NextAccount = y
   
End Function



Private Function CheckDigit(sID As String) As String

'Check Digit Genarator - sID is string length 7

    Dim z As Long
    Dim a(7) As Integer
   
    a(1) = 3
    a(2) = 23
    a(3) = 19
    a(4) = 31
    a(5) = 101
    a(6) = 5
    a(7) = 103
   
   
    For c = 1 To 7
   
        z = z + c * Asc(Mid(sID, c, 1)) * a(c)
       
    Next
   
    CheckDigit = Chr(Asc("0") + z Mod (10))
       
   
       

End Function
0
chaos_59Author Commented:
Thanks, I think I might be able to use this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.