A problem with clearing fields on marked cards

Kay C Lan lan.kc.macmail at gmail.com
Tue Jun 8 02:43:07 EDT 2010

On Tue, Jun 8, 2010 at 12:05 AM, <DunbarX at aol.com> wrote:

> But you can distinguish these fields easily. Why not set a custom property
> in all your fields called "isLabel"?   Set that property of all the label
> fields to "true", and all other fields to "false".
> There may not be a need to set a custom property, for instance their are
several inbuilt properties that are false for text fields and true for label
fields; sharedText and lockText for instance. traversalOn goes the other
way. So why create another property when you could test for those.

Of course you could still set up fields as label fields but aren't actually
labels to a field, maybe a copy right banner at the bottom of a stack, so
the above wouldn't be foolproof but may suffice in your circumstance. If
not, there are other ways to skin this cat. I've gotten into the habit of
prefixing the name of all true label fields with 'lbl', this has other
benefits as well; when you access the property inspector all the label
fields are grouped together - great if you have 100 fields + accompanying
label fields. Finally, and best of all, your text entry fields should all be
'layered' consecutively (Size & Position pane of the Property Inspector),
this makes traversal work better. I do the same with label fields. Then to
do any group entry, validation or clearing it's simply a mater of:

--because you've layered the fields consecutively
--faster because you are not testing if it's a label field
repeat with x = 1 to 88 -- text entry field
   put empty into field x
  --more stuff here if necessary
end repeat

repeat with x = 100 to 187 -- label fields
  set the textColor of field x to red
--more stuff here if necessary
end repeat

Of course if you do the layering correctly, and you want to work with
field/label pairs, knowing the offset where one ends and the other starts
makes it easy to do this:

repeat with x = 1 to 88 -- text entry field
   put empty into field x
  --paired label is offset by 99
  set the textColor of field (x + 99) to red
end repeat

Using fixed numbers isn't going to work if you have a different number of
fields on each card, so that's where custom properties are so useful; easy
to have cEditableFields = 88

repeat with tCardNo = 1 to the number of marked cards
  put the cEditableFields of marked card tCardNo into y
  repeat with x = 1 to y
    put empty into field x of marked card tCardNo
   --more stuff here if necessary
   end repeat
end repeat


More information about the Use-livecode mailing list