Clear variables and 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
Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Clear variables and fields

Post by Philhold » Sat Oct 10, 2009 12:13 pm

Very simple but what is the best way to clear the contents of a field or variable?

This is what I am doing is this correct or is there something better?

Code: Select all

put "" into varA
put "" into field "name"
Thanks

Phil

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

Post by Klaus » Sat Oct 10, 2009 1:29 pm

Hi Phil,

...
put empty into fld "xyz"
...
is the best, if not the only way :-)
Same for emptying variables.


Best

Klaus

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Sat Oct 10, 2009 2:23 pm

Hi Klaus,

Many thanks, your help is very much appreciated.

I'm actually getting my first little app to work.

Cheers

Phil

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

Post by Klaus » Sat Oct 10, 2009 2:29 pm

[qHi Phil,

you're welcome!

And of course "" is the same as -> empty!


Best

Klaus

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Sat Oct 10, 2009 6:08 pm

and this would clear all fields would it?

repeat with x = 1 to number of fields
put empty into fld x
end repeat

any dangers in doing this? Does it just clear all fields on the current card?

Cheers

Phil

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Sun Oct 11, 2009 4:17 pm

Your script will indeed clear all the fields on the current card - including label fields, so you have to be careful! If you want to empty all the editable fields in your stack, you would have a loop like this:

Code: Select all

on mouseUp
  local tCardCount, tCardIndex, tFieldCount, tFieldIndex
  put the number of cards into tCardCount
  repeat with tCardIndex = 1 to tCardCount
    put the number of fields of card tCardIndex into tFieldCount
    repeat with tFieldIndex = 1 to tFieldCount
      if the lockText of field tFieldIndex of card tCardIndex is false
      then put empty into field tFieldIndex of card tCardIndex
    end repeat
  end repeat
end mouseUp
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Philhold
Posts: 64
Joined: Thu Mar 05, 2009 3:39 pm

Post by Philhold » Sun Oct 11, 2009 4:43 pm

Hi Jan,

Many thanks for the tip.

Your script has stimulated me to search around but I can't find the answer. By implication am I right to assume that the lockText of label fields is set to true by default?

Thanks

Phil

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

Post by Klaus » Sun Oct 11, 2009 6:47 pm

Hi Phil,

definitivley maybe! :-D

No just kidding, you are presuming correctly, "label" fields are "locked" by default.


Best

Klaus

Post Reply