Hello, I have a variable = 0010010100000001 and want to add a "1" (as if it was a consecutive number)so the resulting number is 0010010100000002. I appreciate any help or advise.

Hello, I have a variable = 0010010100000001 and want to add a "1" (as if it was a consecutive number)so the resulting number is 0010010100000002. I appreciate any help or advise.

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 )

)

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 re-instated even if the text concatonation result is returned as type text.

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 001-001-01-00000001, 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

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.

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.

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>

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>

interesting.

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.