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?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

brandonbConnect With a Mentor Commented:
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


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.
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.


'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
        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)
    CheckDigit = Chr(Asc("0") + z Mod (10))

End Function
chaos_59Author Commented:
Thanks, I think I might be able to use this.
All Courses

From novice to tech pro — start learning today.