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....
Sub total a list
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Sub total a list
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.
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
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
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
Thanks... that worked...
Re: Sub total a list
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
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