Empty a lot of fields at once

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
pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Empty a lot of fields at once

Post by pink » Wed May 07, 2014 7:03 pm

Right now, I have 20 fields that I put empty into; and also I put 0 into 35 fields on a mouseUp... is there a faster way of clearing a lot of fields at once?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Empty a lot of fields at once

Post by Klaus » Wed May 07, 2014 7:08 pm

Hi pink,

you need to do a repeat loop like this:

Code: Select all

...
## Always lock the screen when updating lot of controls!
lock screen
repeat with i = 1 to 20
  put EMPTY into fld i
end repeat
unlock screen
...

Code: Select all

...
## Always lock the screen when updating lot of controls!
lock screen
repeat with i = 1 to 35
  put "0" into fld i
end repeat
unlock screen
...
Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Empty a lot of fields at once

Post by dunbarx » Wed May 07, 2014 7:14 pm

Hi.

Have you ever written a repeat loop? I like to make new users do their own work. (So everyone else, back off) Please read up on the "repeat" control structure in the dictionary, especially its "repeat with" variant.

Think about the following (pseudocode)

loop through all the fields on the card --how shall we reference each one?
put empty into each field --looks like you have done this sort of thing already

Write back as soon as you have something, or have questions or problems.

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Empty a lot of fields at once

Post by dunbarx » Wed May 07, 2014 7:15 pm

Pay no attention to what Klaus wrote. Do it my way.

Craig

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Empty a lot of fields at once

Post by Klaus » Wed May 07, 2014 8:01 pm

dunbarx wrote:Pay no attention to what Klaus wrote. Do it my way.

Craig
:D :D :D

pink
Posts: 272
Joined: Wed Mar 12, 2014 6:18 pm

Re: Empty a lot of fields at once

Post by pink » Fri May 09, 2014 9:01 pm

Thanks Craig & Klaus, you were both a big help

I put two fields on a card that just holds some data and the fields that need to be reset get put into it as theya re being processed.
This is what I ended up using:

Code: Select all

     repeat for each line fieldToEmpty in field "fieldlist" on card "data"
          do "put empty into field"&quote&fieldToEmpty&quote 
     end repeat
     repeat for each line fieldToZero in field "fieldlistcounters" on card "data"
          do "put 0 into field"&quote&fieldToZero&quote
     end repeat
Thanks again for your help
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Empty a lot of fields at once

Post by Klaus » Fri May 09, 2014 9:23 pm

Hi pink,

you're welcome! :D

But no need to DO something here!

Code: Select all

...
     repeat for each line fieldToEmpty in field "fieldlist" of card "data"
          put empty into field fieldToEmpty
     end repeat
     repeat for each line fieldToZero in field "fieldlistcounters" of card "data"
         put 0 into field fieldToZero 
     end repeat
...
will do!

Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”