blindbo Posted August 8, 2003 Posted August 8, 2003 Given a number, say 2345678, I need to add up the ODD position digits and multiply the sum by 3. Then add up the EVEN position digits. Both sums are then added together. Finally, determine the value required to bring that sum up to the next multiplier of 10. Example: 1. Calc of the odd position digits:(2+4+6+8)3 = 60 2. Calc of the even position digits: 3+5+7 = 15 3. Sum of both: 60+15 = 75 4. Value needed to bring 75 to the next multiplier of 10 (80) = 5 Any help from a REAL LEFT BRAINER is greatly appreciated!
Lee Smith Posted August 8, 2003 Posted August 8, 2003 Hi blindbo, I came up with a real convoluted way, maybe others will make it smoother, but at least it will give you something to think about. HTH Choose.fp5.zip
blindbo Posted August 8, 2003 Author Posted August 8, 2003 Lee, I may have been unclear in my problem description. I need to sum the digits that FALL into the odd, or even POSITIONS of the string. To say it another way, the "odd" calc is the sum of the digits in the first, third, fifth, seventh...etc postion. Whereas the 'even' calc is the second, fourth, sixth...etc., position. Any thoughts on that one? (I hope!)
Fitch Posted August 8, 2003 Posted August 8, 2003 You might need NumToText() to make the number into a string. Then use the Middle() function in combination with Position(). If the number is arbitrarily big, you might set up a field to use as a counter, set it to the Length() of the number, then increment it down to 0 in a Loop script. Each time through the Loop, you'd add a digit until the counter reaches 0. I don't understand why you need to add the odd and even digits up separately if you're going to just add those two sums anyway. Why not just add up all the digits in the first place? Finally, Mod(yourSum, 10) will give you what's left over when you divide by 10. So, 10 - Mod(yourSum, 10) will give you the number you're after.
Lee Smith Posted August 8, 2003 Posted August 8, 2003 Hi blindbo, This was actually easier than what I had come up with, man did I ever missread your first post. I have made changes using Tom's Mod calculation which is much better than the one I used. Thanks Tom, Anyway, I hope this is closer to what you need. Lee Choose.fp5.zip
blindbo Posted August 8, 2003 Author Posted August 8, 2003 Tom: The first sum is multiplied by three, therefore it needed to be parsed out. Thanks for the reply as it was apparently a switch to another great light bulb in Lee's head! Lee: YES! That works! Thank you so very, very much. This was beyond my current knowledge. Anyone reading: This application is used to create a digit which is appended to the original number. This final number is used as a sequencing number for bank checks. When the check is scanned, it is validated by the check sum digit.
Lee Smith Posted August 8, 2003 Posted August 8, 2003 [color:"blue"]Anyone reading: This application is used to create a digit which is appended to the original number. This final number is used as a sequencing number for bank checks. When the check is scanned, it is validated by the check sum digit. Now that I know what you want this for, you might want to check out this file by Ray J. Cologon aka CobaltSky around here Dynamic Check Digits - Modulus 10 and Modulus 11! http://www.nightwing.com.au/FileMaker/ It might be of some value to you. HTH Lee
BobWeaver Posted August 8, 2003 Posted August 8, 2003 Create a global number field, "Index" with 5 repetitions and put the numbers 1, 2, 3, 4, 5 into the respective repetitions. Create a calculation field "ChecksumDigits" with 5 repetitions with the formula: Middle(Extend(InputNo), Index*2-1, 1)*3+Middle(Extend(InputNo), Index*2, 1) Finally create a calculation field "Checksum" with the formula: Mod(Sum(ChecksumDigits),10) See attached sample file Checksum.fp5.zip
Lee Smith Posted August 8, 2003 Posted August 8, 2003 Hi Bob, If you use the number 2589115 we get different numbers for the check sum. I get 5, and yours gives 3. Question is, who's is correct? Lee p.s., I tried to write you back channel but I see you don't receive Private Messages.
BobWeaver Posted August 9, 2003 Posted August 9, 2003 Actually, looking at it again, I think we are both wrong. Doing the calculation by hand, I get: Odd digits: (2+8+1+5)*3=48 Even digits: 5+9+1=15 Total 15+48=63 Next higher multiple of 10=70 Checksum=70-63=7 (My formula had been doing a Mod 10 here and got 3 as a result) I'm not sure how you came up with 5. The formula for my Checksum field should be changed to: Mod(1000-Sum(ChecksumDigits),10) See the new attachement. Sorry about my Private messages being switched off. I was getting way too many general Filemaker questions that should have been posted to the forums. So, I decided to shut it down. Checksum.fp5.zip
BobWeaver Posted August 9, 2003 Posted August 9, 2003 Lee: I checked your formula and it gives the correct value of 7 not 5.
Lee Smith Posted August 9, 2003 Posted August 9, 2003 Hi Bob, I had just used the one Tom posted, although my original formula had also gaven the same answer, which made me wonder what was wrong. Now, I need to examine your formula for my future need: 10 - Mod(AddEvenAndOdd Copy, 10) [color:"blue"]> I was getting way too many general Filemaker questions that should have been posted to the forums. So, I decided to shut it down. I have had this problem too lately. Most of the time I just tell them to post to the forum and get more and probably better answers. Lee
BobWeaver Posted August 9, 2003 Posted August 9, 2003 Lee, This formula 10 - Mod(AddEvenAndOdd Copy, 10) can give the incorrect value of 10 instead of zero. It will give you the correct value of zero if you change it to: Mod(1000-AddEvenAndOdd Copy, 10) or to: Mod(10-Mod(AddEvenAndOdd Copy, 10),10) I assumed that Blindbo wants a single digit checksum. Hence, 0 rather than 10.
Lee Smith Posted August 9, 2003 Posted August 9, 2003 Hi Bob, Thanks for the education, I really appreciate it. I hope that Blindbo comes back and catches up on this. Lee
BobWeaver Posted August 9, 2003 Posted August 9, 2003 BTW, If you have looked at some of my posts recently, you may have noticed that I have started using a bunch of calculations based on repeating fields which reference a global repeating field containing the values 1, 2, 3, 4... etc. I've found that you can solve some fairly complex problems with very simple calculations this way. The drawback is that the result must be unstored and therefore is not indexable.
Lee Smith Posted August 9, 2003 Posted August 9, 2003 Hi Bob, [color:"blue"]> The drawback is that the result must be unstored and therefore is not indexable. Easily overcome by a simple script and another field. Thanks again, Lee
blindbo Posted August 13, 2003 Author Posted August 13, 2003 Bob, You are correct that I needed a single digit checksum, "0", instead of "10". Lee's solution gave me the correct checksum, but did leave the 2-digit "10". I simply made a conditional statement to handle that (that much left-brained, I am!! LOL) Thanks again, Lee!
Recommended Posts
This topic is 7773 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now