Addition-Elementary Style

J. Landman Gay jacque at hyperactivesw.com
Wed Jan 25 16:42:08 EST 2006


Michael Mandaville wrote:
> Revolution brothers and sisters,
> On the basis that the most stupid question is the one left unasked,

You bet, and I wish more people would ask the basic stuff. Good going.

> I throw
> myself on the pyre with this question:
> 
> I have eight multiple text fields.  Numbers will go into these fields.  I
> want all the numbers to add up and go into the Ninth field.

Transcript being as flexible as it is, there are about a gazillion ways 
to do this. Here are three, from longest to shortest:

1. Use "add" sequentially:

put fld 1 into myTotal -- put in the initial value
add fld 2 to myTotal
add fld 3 to myTotal
... etc
put myTotal into fld 9


2. Use "add" in a repeat loop:

repeat with x = 1 to 8
   add fld x to myTotal
end repeat
put myTotal into fld 9

3. Use the built-in "sum" function:

   put sum(fld 1,fld 2,fld 3,fld 4,fld 5,fld 6,fld 7,fld 8) into fld 9


You can substitute the field's name for the number in any of these. 
I.e.: add fld "effort" to mytotal, etc.


-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list