Page 1 of 1
adding a row of numbers in field
Posted: Mon Aug 03, 2015 12:58 pm
by mister
I have a tab delimited field where each row contains a name followed by hours worked for the week. How do I add the total hours worked?
Thanks,
Larry
Re: adding a row of numbers in field
Posted: Mon Aug 03, 2015 1:18 pm
by Klaus
Hi Larry,
I have a tab delimited field...
this is the important part of the answer
Make a repeat loop through the field and use TAB as itemdelimiter, something like this:
Code: Select all
...
set itemdel to TAB
put 0 into totalhours
repeat for each line tLine in fld "hours worked"
## Supposed the hours are the second item per line:
add item 2 of tLine to totalhours
end repeat
## Now do whatever you want with totalhours
...
Best
Klaus
Re: adding a row of numbers in field
Posted: Mon Aug 03, 2015 3:20 pm
by dunbarx
Hi.
What Klaus said.
But what he assumes is that the name portion of each line and the hours portion are indeed separated by tabs. Is this so? It matters because his whole point is that LC can distinguish the two portions based on the tab character delimiting them, one portion on each "side" of the tab, those then becoming separate "items" within each line.
Perhaps this is all well known to you. Just making sure...
Craig Newman