Page 1 of 1

Sub total a list

Posted: Fri Jun 22, 2012 9:48 pm
by dantomlin
I have a list of the following data:

CounterKicks, 1000
CounterKicks, 900
BallisLife, 1200
BallisLife, 500
HoopMix, 1000

I need to write a loop so I can get a sub-total for each item (word 1 of the list).
My result s/b:
Counterkicks, 1900
Ballislife, 1700
HoopMix, 1000

I can get the loop to put 3 lines in my result with the correct names but I can't seem to get the amounts to add up correctly.

Any help would be greatly appreciated.... :)

Re: Sub total a list

Posted: Fri Jun 22, 2012 10:21 pm
by sturgis
Probably the easiest way to do this would be with an array. If the data is in a variable say sData you can use the first item as the array key and then just keep adding as you go through the items.

Code: Select all

repeat for each line tLine in sData -- go through all the lines of sdata
 add item 2 of tLine to sDataA[item 1 of tLine]
end repeat
This will create an array similar to the following.

sDataA["CounterKicks"] has the value of 1900
sDataA["BallisLife"] has the value of 1700
sdataA["HoopMix"] is of course 1000

Re: Sub total a list

Posted: Mon Jun 25, 2012 5:10 pm
by dantomlin
Thanks... that worked... 8)

Re: Sub total a list

Posted: Wed Jul 04, 2012 12:16 am
by NoN'
Hi,
An exemple of implementation of sub total realised with HC/Livecode can be find here :

http://rg75.free.fr/hyperespace.T_AlK.fr.htm

It is probably the easiest way to do this kind of thing.
Only in french, for the moment, but the english version should come soon.

Regards,

Renaud