adding / subtracting numbers

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dantomlin
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 43
Joined: Tue Feb 26, 2008 4:07 pm

adding / subtracting numbers

Post by dantomlin » Fri Feb 12, 2010 10:20 pm

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

RRobert
Posts: 151
Joined: Sat Feb 28, 2009 8:20 pm

Re: adding / subtracting numbers

Post by RRobert » Fri Feb 12, 2010 11:35 pm

I would split the string by minus, plus ..., setup another array with the signs and write a function that does the math.

Robert

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: adding / subtracting numbers

Post by Regulae » Sat Feb 13, 2010 12:38 am

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.

dantomlin
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 43
Joined: Tue Feb 26, 2008 4:07 pm

Re: adding / subtracting numbers

Post by dantomlin » Sat Feb 13, 2010 5:10 pm

thanks, that worked.... so simple 8)

Post Reply