Use repeat to clear ever field in a group

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
RalphORama
Posts: 7
Joined: Wed Oct 22, 2014 5:19 pm

Use repeat to clear ever field in a group

Post by RalphORama » Tue Nov 11, 2014 5:54 pm

Hello! I'm trying to write a repeat to clear every field in a group, but I can't seem to make it work. Here's my current code:

Code: Select all

repeat for each field tClearField in group "displayGrp" -- put the name of the field into tClearField
     put "" into field tFieldClear -- clear the field
end repeat
With this code, I'm getting the error group "keypadGrp": compilation error at line 10 (repeat: bad termination condition) near "field", char 21

I'm not sure where to go with this, the other thing I've tried for debugging purposes is:

Code: Select all

answer the number of fields in group "displayGrp"
This properly returns the number of fields in the group.

How could I get this to work?

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Use repeat to clear ever field in a group

Post by LCNeil » Tue Nov 11, 2014 6:04 pm

Hi TalphoRama,

The repeat for each syntax relies on a chunk expression to work as expected (e.g repeat for each line, repeat for each char, repeat for each word..) so this form of repeat will result in an error if used in the context of your script.

Another repeat that you should be able to use is "repeat with var =". The following is an example of this which will clear all fields in the group-

Code: Select all

on mouseUp
   repeat with x = 1 to the number of fields in group "displayGrp" -- put the name of the field into tClearField
      put "" into field x of group "displayGrp"-- clear the field
   end repeat
end mouseUp
Kind Regards,

Neil Roger
--
LiveCode Support Team ~ http://www.livecode.com
--

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10087
Joined: Fri Feb 19, 2010 10:17 am

Re: Use repeat to clear ever field in a group

Post by richmond62 » Tue Nov 11, 2014 8:32 pm

Rather than

put " "

I always prefer

put empty

then the field IS really empty.

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

Re: Use repeat to clear ever field in a group

Post by Klaus » Tue Nov 11, 2014 10:07 pm

richmond62 wrote:Rather than
put " "
I always prefer
put empty
then the field IS really empty.
and with -> put "" it's only half empty? 8)

:D

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Use repeat to clear ever field in a group

Post by Mark » Tue Nov 11, 2014 10:09 pm

Klaus, I prefer half full ;-)

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Re: Use repeat to clear ever field in a group

Post by dunbarx » Tue Nov 11, 2014 11:38 pm

Richmond is not just being pedantic. It is easy to inadvertently put a space, or even an invisible char in between those quotes. But "empty" is empty.

That said, I never do it. Lazy, you know.

Craig

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Use repeat to clear ever field in a group

Post by Mark » Tue Nov 11, 2014 11:49 pm

Actually, I always use empty instead of two double quotes. It makes it easier to read the code.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply