Page 1 of 1

adding / subtracting numbers

Posted: Fri Feb 12, 2010 10:20 pm
by dantomlin
any ideas on how I would add and/or subtract a string of numbers? I was able to figure it out if the string is only adding numbers but not both.

For example:
a user would enter numbers into a field (similar to a spreadsheet) like 100+200+300 and then hit enter. I want to then show the total which would be 600. again, I was able to write a function to do that but what if the string had a combination of "+" and "-"... like 100+200+300-50 or 100-50+200-75....

Thanks, Dan

Re: adding / subtracting numbers

Posted: Fri Feb 12, 2010 11:35 pm
by RRobert
I would split the string by minus, plus ..., setup another array with the signs and write a function that does the math.

Robert

Re: adding / subtracting numbers

Posted: Sat Feb 13, 2010 12:38 am
by Regulae
This might not be what you want, but if you have, for example, a field “test”, and type in:
10 + 20 – 5
... then, in the message box, enter:
put field “test”
... it will return:
“10 + 20 – 5”
If instead you enter:
put the value of field “test”
... it returns the computed value:
“25”
Thus “the value of” a container gives you, in this case, the computed value.

Re: adding / subtracting numbers

Posted: Sat Feb 13, 2010 5:10 pm
by dantomlin
thanks, that worked.... so simple 8)