Page 1 of 1
Use repeat to clear ever field in a group
Posted: Tue Nov 11, 2014 5:54 pm
by RalphORama
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?
Re: Use repeat to clear ever field in a group
Posted: Tue Nov 11, 2014 6:04 pm
by LCNeil
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
--
Re: Use repeat to clear ever field in a group
Posted: Tue Nov 11, 2014 8:32 pm
by richmond62
Rather than
put " "
I always prefer
put empty
then the field IS really empty.
Re: Use repeat to clear ever field in a group
Posted: Tue Nov 11, 2014 10:07 pm
by Klaus
richmond62 wrote:Rather than
put " "
I always prefer
put empty
then the field IS really empty.
and with -> put "" it's only half empty?

Re: Use repeat to clear ever field in a group
Posted: Tue Nov 11, 2014 10:09 pm
by Mark
Klaus, I prefer half full
Mark
Re: Use repeat to clear ever field in a group
Posted: Tue Nov 11, 2014 11:38 pm
by dunbarx
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
Re: Use repeat to clear ever field in a group
Posted: Tue Nov 11, 2014 11:49 pm
by Mark
Actually, I always use empty instead of two double quotes. It makes it easier to read the code.
Best,
Mark