Zum Hauptinhalt gehen

Suche

Suche

Mod 10 Overflow

Kommentare

2 Kommentare

  • Avatar
    Michael Toupin (mtoupin
    MOD functions don't work on strings longer than the limit of a Long data type, or 2,147,483,647. A script to emulate that command for larger numbers is: value = (value - int(value / 10) * 10)
    0
  • Avatar
    Permanently deleted user

    I want to add something to this.  The built in VB Script "Mod" operator is a mathematical function that has nothing directly to do with check digits.  It is the remainder if you divide by a number.  So "7 mod 3" means "what is left over if I divide 7 by 3".  7 divided by 3, using only whole numbers, is 2, with a remainder of 1.  (or using fractions, 2 1/3, and note the remainder is the numerator of the fractional part.)  See "modulo operation" in Wikipedia to understand this better.

     

    So your code fails for the reason Mike stated - the number is bigger than VB Script can handle as a numeric value.

     

    Now, most check digits are calculated by taking a sum of the digits, or sometimes a weighted sum of the digits, and you might get a sum like "245" out of it, which you then take "Mod 10" and it gives you 5.  So the VB Script "Mod" operator may wind up being used in a custom check digit calculation, but you can't simply apply "Mod 10" to a string.

     

    To solve this problem you would need to find a spec on how the check digit is calculated for this particular requirement.  To get an idea how it works, search for "Luhn algorithm" on wikipedia.  This is not the algorithm you need (as you already figured out) however it gives you an idea of the type of technical info you need to find in order to implement this check digit.  If you get stuck someone can help but not without the specification (or at least the official name) of the check digit you need.

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.