
1. Re: Adding numbers with tracking zeros
PeterWindle Jul 8, 2016 10:36 PM (in response to yomango)1 of 1 people found this helpfulinteresting.
variables are a double edged sword, on the one hand, they are great at being able to "assume" the content type... or the other hand, we all know what happens when you "assume"... ;)
There are perhaps a kazillion ways to resolve this, but here is a suggestion:
set the first initial variable value to a text value (surround the number in quotes)
set variable $numberastext to "0010010100000001"
then grab the number as a number
set variable $number as getasnumber($numberastext)
then comes the fun part... well, you could increment the number then add the leading zeros, but this could get messy if you don't know how many leading zeros there may be.
what I did was to perform a substitute on the value:
set variable $result to substitute ($numberastext, $number, $number +1)
simple enough, I guess you might want to be careful when using substitute because if for some reason the pattern of numbers is repeated somehow in the original string, then you're in trouble, but in this case, it's not a problem.
I'm sure the other wonderful developers in the forum have better solutions.

2. Re: Adding numbers with tracking zeros
alangodfrey Jul 9, 2016 3:19 AM (in response to PeterWindle)Would the number ever be like:
0010010100000099
or even worse,
099999999999999?

3. Re: Adding numbers with tracking zeros
PeterWindle Jul 9, 2016 3:37 AM (in response to alangodfrey)good point!

4. Re: Adding numbers with tracking zeros
alangodfrey Jul 9, 2016 7:33 AM (in response to PeterWindle)Is it always 16 characters long? If so, you could try:
Right ( "0000000000000000" & YourNumber + 1 ; 16 )
if it can be of variable length you could calculate the length first and adjust the length of the padded number.
Updated to accommodate any number up to the number of zeros shown in the string:
Let (
[ Len = Length ( NumberOriginal ) ] ;
Right ( "00000000000000000000000000000000000000" & ( NumberOriginal + 1 ) ; Len )
)

5. Re: Adding numbers with tracking zeros
alangodfrey Jul 9, 2016 8:05 AM (in response to alangodfrey)Just a warning about the limitations of that calculation. The 'NumberOriginal' field and the 'NumberIncreasedBy1' field are both specified as type text.
I was curious to see what would happen if I introduced a letter into the sequence. This is what I got:
Number Original: 000111a
Number Increased: 0000112
or
Number Original: 0001a11
Number Increased: 0000112
So it will not do what you want if there are any alpha characters in the string.
The performing of an addition to the NumberOriginal seems to make Filemaker recognise it as a number and strip out any alpha characters, which will not be reinstated even if the text concatonation result is returned as type text.

6. Re: Adding numbers with tracking zeros
yomango Jul 9, 2016 9:16 AM (in response to yomango)Thank you all for your time and interest. I will try your suggestions to see which one works best. I did not mention that the original number comes out formatted as 0010010100000001, where the last "1"is the consecutive. Since I have to grab the last consecutive to create the new one, I take the dashes "" while setting the variable. I believe it won't hinder the suggested calculations, would it?. Muchas gracias

7. Re: Adding numbers with tracking zeros
yomango Jul 9, 2016 9:31 AM (in response to alangodfrey)Hello. I used Getastext(Right ( "0010010100000000" & 2+ 1 ; 16 )) and get 0100101000000003 missing the left most zero "0" and if getasnumber(Right ( "0010010100000000" & 2+ 1 ; 16 )) is used, the two left most zeros are missing: 100101000000003 . If a use the calculation without the "Get" function , the result is 0100101000000003. getting closer to what I need, though.

8. Re: Adding numbers with tracking zeros
yomango Jul 9, 2016 11:16 AM (in response to PeterWindle)Hello, PeterWindle. Your suggestion DID IT! Thank you. The final calculation on the script is:
$ID_Invoice=
Let ( [$ID=Left(T12_INVOICES::ID_Invoice;3) & Middle(T12_INVOICES::ID_Invoice;5;3) & Middle(T12_INVOICES::ID_Invoice;9;2 )& Right(T12_INVOICES::ID_Invoice;8);
O=GetAsText($ID);
N=GetAsNumber(O)] ;
Substitute ( O; N ; N+1)
)
And the resulting variable is pasted on the next consecutive invoice field.
(The $ID removes all dashes "" from T12_INVOICES::ID_Invoice field)
Muchas gracias por su tiempo.

9. Re: Adding numbers with tracking zeros
BruceRobertson Jul 9, 2016 1:28 PM (in response to yomango)1 of 1 people found this helpfulLearn more about the SerialIncrement function.
It was designed to do exactly this.
Let( myNum = "0010010100000001"; serialIncrement( myNum; 1))
=> "0010010100000002"
Let( myNum = "0010010100000099"; serialIncrement( myNum; 1))
=> "0010010100000100"

10. Re: Adding numbers with tracking zeros
yomango Jul 9, 2016 2:03 PM (in response to BruceRobertson)Thank you, Bruce. The formula looks very simple once one knows it exists.
De: BruceRobertson
Enviado el: Saturday, July 9, 2016 2:29 PM
Para: Mauricio Navarro <basesdedatosfmp@gmail.com>
Asunto: Re:  Adding numbers with tracking zeros
Adding numbers with tracking zeros
reply from BruceRobertson <https://community.filemaker.com/people/BruceRobertson?et=watches.email.thread> in Discussions  View the full discussion <https://community.filemaker.com/message/585403?et=watches.email.thread#585403>

11. Re: Adding numbers with tracking zeros
Extensitech Jul 9, 2016 2:07 PM (in response to BruceRobertson)Wow. I'd never seen this one, either. Just goes to show that learning never ends.
At least this time I found out about the function before I wrote a custom function for it.
Chris Cain
Extensitech

12. Re: Adding numbers with tracking zeros
BruceRobertson Jul 9, 2016 3:06 PM (in response to Extensitech)Originated in Filemaker 7!

13. Re: Adding numbers with tracking zeros
yomango Jul 9, 2016 3:16 PM (in response to BruceRobertson)Yes. As Chris Cain of Extensitech said, one never ceases learning.
De: BruceRobertson
Enviado el: Saturday, July 9, 2016 4:07 PM
Para: Mauricio Navarro <basesdedatosfmp@gmail.com>
Asunto: Re:  Adding numbers with tracking zeros
Adding numbers with tracking zeros
reply from BruceRobertson <https://community.filemaker.com/people/BruceRobertson?et=watches.email.thread> in Discussions  View the full discussion <https://community.filemaker.com/message/585435?et=watches.email.thread#585435>

14. Re: Adding numbers with tracking zeros
keywords Jul 9, 2016 3:49 PM (in response to yomango)A new one on me too. That's why my motto is "always learning".
Please mark Bruce's post as correct, so he gets the brownie points and others can more easily find it.