Clearing a lot of fields

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

Clearing a lot of fields

Post by Glenn Boyce » Mon Aug 10, 2009 3:43 am

Someone once gave me some code for clearing a whole lot of fields on a card with out writing "put "" into fld "fieldname"" for each one. I have a very busy card and need a clear button on it and think that now is the time to use that piece of code!! Any help appreciated.
Cheers

Glenn

edljr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sun Oct 26, 2008 6:47 am
Contact:

Clearing a lot of fields

Post by edljr » Mon Aug 10, 2009 4:49 am

Glenn,

Try this:

Code: Select all

on mouseUp
   put the number of fields on this card into lastField
   repeat with x = 1 to lastField
      put empty into fld x
   end repeat
end mouseUp
Ed
http://idleaders.com

Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

Clearing fields

Post by Glenn Boyce » Mon Aug 10, 2009 5:20 am

Great that cleared them all right. BUT it also cleared all the label fields as well!! I just want to clear the ones I have entered data into.

cheers

edljr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sun Oct 26, 2008 6:47 am
Contact:

Clearing a lot of fields

Post by edljr » Mon Aug 10, 2009 5:37 am

Glenn,

If you have a naming convention that differentiates your label fields from data entry fields, this is easy. For example, you can name all your labels with the preface "label" (i.e. labelName, labelStreet, labelCity). Then you could ignore those fields in the below code:

Code: Select all

on mouseUp
   put the number of fields on this card into lastField
   repeat with x = 1 to lastField
      put the short name of fld x into tFld
      if tFld contains "label" then
         // do nothing
      else
         put empty into fld x
      end if
   end repeat
end mouseUp
HTH,
Ed
--
Ed Lavieri
three19
www.three19.com
--

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

Post by Klaus » Mon Aug 10, 2009 9:59 am

Hi Glenn,

"label" fields have their "locktext" property set to true, so you better check for this prop than for the name, which may NOT contain "label" :-)

Code: Select all

on mouseUp 
   put the number of fields on this card into lastField 
   repeat with x = 1 to lastField 
      if the locktext of fld x <> true then 
          put empty into fld x 
      end if 
   end repeat 
end mouseUp 
Best

Klaus

Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

Post by Glenn Boyce » Mon Aug 10, 2009 9:41 pm

Thank you. Got an answer that'll work.

Post Reply