Hi Glen,
"repeat for each line tLine..." will surely be the fastest way to do wat you want!
Another way may to use an ARRAY and extract the wanted column from that:
Code: Select all
...
put field "your field here" into tArray
## Turn it into an array:
split tArray by column
## Extract your second column
put tArray[2] into tColumn
## I will use the SUM function which demands a comma delimited itemlist
replace CR with "," in tColumn
## Now you got what you need:
put sum(tColumn) into MyN
...
I doubt this is faster than the first method, but there are always may ways to skin a cat in LiveCode
I would put this into a function like this:
## With tColumn you could also add the number of your desired column,
## so this finction is even more "versatile"
## Of course you can "hard code" the column number and omit that parameter.
Code: Select all
function addColumns tData, tColumn
split tData by column
## Extract your seocnd column
put tData[tColumn] into tColumn1
## I will use the SUM function which demands a comma delimited itemlist
replace CR with "," in tColumn1
## Now you got what you need:
return sum(tColumn1)
end addColumns
Then call it with:
...
put fld "xyz" into tData
answer addColumns(tData,2)
...
Best
Klaus