adding a row of numbers in field

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mister
Posts: 39
Joined: Thu Nov 27, 2014 9:03 pm

adding a row of numbers in field

Post by mister » Mon Aug 03, 2015 12:58 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: adding a row of numbers in field

Post by Klaus » Mon Aug 03, 2015 1:18 pm

Hi Larry,
I have a tab delimited field...
this is the important part of the answer :D

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: adding a row of numbers in field

Post by dunbarx » Mon Aug 03, 2015 3:20 pm

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

Post Reply