4 Replies Latest reply on Mar 20, 2013 1:03 PM by philmodjunk

Calculate control sum

Title

Calculate control sum

Post

I need to calculate a control number. As a function.

Its using the modulus 10 method with the weights 2 and 1. Example:

860324-0261 this is a 9 digit number with a 10th control number (=1).

212121 212 factorize with these numbers.

16,6,0,3,4,4,0,2,12 will give theses results

1+6+6+0+3+4+4+0+2+1+2 = 29. 9 is the last digit. 10-9=1. Control number is 1. Function would return true, since its correct. If the input number is anything else than 10 digits after stripping away the dash it shall also return false.

So, with php I would know how to do, but FileMaker functions can't contain loops. Anyone have an idea?

• 1. Re: Calculate control sum

Are you converting isbn10 to isbn13?  I did app last year for someone than converts isbn10 to isbn13 and isdn13 to isdn 10. It uses a formual similar to the above.  My solution isn't pretty by any means but it get the job done.  In any manner maybe this sample app will help you figure out your answer.

https://www.sugarsync.com/pf/D9559058_790_868748394

• 2. Re: Calculate control sum

FileMaker functions can contain loops. Using FileMaker Advanced, you can create a custom recursive function to get loops. You may find that there is already a custom function for this if you search one of the FileMaker custom function web sites.

• 3. Re: Calculate control sum

S Chamblee: No, its a database containing companies, and all national company id numbers works the same way as swedish social security numbers, you can check the validly of the number by this method. (social security numbers is only used for id, not for authentication in sweden)

Using web sources to retrieve information about the company is too slow in this process, as soon as the customer has said their number it needs to be validated immediately since it will decide the next question to the customer. I actually had in mind to use it as a conditional format, with light green background in the field if it validated correctly, and light red if not.

PhilmodJunk: I have to look deeper in that then. Thanks.

• 4. Re: Calculate control sum

I produced the following pair of custom functions that will return 1 (True) when the digits entered match the checksum final digit and 0 when the number of characters entered is not 10 or if they don't produce a matching checksum:

//DigitSum ( Digits )
//
//Returns sum of string of digits passed as Digits
//
Case ( IsEmpty (Digits ) ; "" ;
Left ( Digits ; 1 ) + DigitSum ( Right ( Digits ; Length ( Digits) - 1 ) )
)

//CheckSum ( CodeString )
//
//Performs a checksum on CodeString, validating the length of the string and comparing the result to the last digit of codestring to confirm that codestring is valid
//
Case ( Length ( CodeString ) = 10 ;
10 - Mod ( DigitSum ( Middle ( CodeString ; 1 ; 1 ) * 2 &
Middle ( CodeString ; 2 ; 1 ) &
Middle ( CodeString ; 3 ; 1 ) * 2 &
Middle ( CodeString ; 4 ; 1 ) &
Middle ( CodeString ; 5 ; 1 ) * 2 &
Middle ( CodeString ; 6 ; 1 ) &
Middle ( CodeString ; 7 ; 1 ) * 2 &
Middle ( CodeString ; 8 ; 1 ) &
Middle ( CodeString ; 9 ; 1 ) * 2
) ; 10 ) = Right ( CodeString ; 1 ) ;
False // Codestring isn't 10 characters in length
) // Case

To validate text in a given text field, I'd use this expression in a script:

If [ CheckSum ( Filter (YourTable::YourTextFieldHere ; 9876543210 ) ) ]

Custom functions require FileMaker Advanced to create/install in a FileMaker Database file, but once installed it will work with FileMaker Pro. If you do not have FileMaker Advanced, you can't create such custom functions, but you can create a looping script that produces the same result.