Optimizing variable declarations [SOLVED]

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
atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Optimizing variable declarations [SOLVED]

Post by atout66 » Fri Apr 04, 2014 9:44 am

Hi to all,

I'm wondering if there is a way to optimize multiple variable declarations of the same type...
Let say I have to empty many fields with different names each; NOT like "fld01", "fld02", and so on, which I could instantiate by a repeat loop.
In few words, how can I avoid this:

Code: Select all

put empty into fld "myFld"
put empty into fld "myOtherFld"
put empty into fld "otherFld"
etc.
I tried this without success:

Code: Select all

put empty into fld "myFld" , "myOtherFld" ,  "otherFld"
Any idea around ?
Last edited by atout66 on Fri Apr 04, 2014 1:10 pm, edited 1 time in total.
Discovering LiveCode Community 6.5.2.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Optimizing variable declarations

Post by Thierry » Fri Apr 04, 2014 9:58 am

atout66 wrote:Hi to all,
I tried this without success:

Code: Select all

put empty into fld "myFld" , "myOtherFld" ,  "otherFld"
Any idea around ?
Bonjour,

what about this:

Code: Select all

put "myFld" , "myOtherFld" ,  "otherFld" into ListOfFieldsToEmpty

repeat for each item aField in ListOfFieldsToEmpty
     put empty into field aField
end repeat
Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Optimizing variable declarations

Post by atout66 » Fri Apr 04, 2014 1:09 pm

You've got it Thierry, merci beaucoup :wink:
It was the right approach, a loop...

Cheers
Discovering LiveCode Community 6.5.2.

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

Re: Optimizing variable declarations [SOLVED]

Post by dunbarx » Fri Apr 04, 2014 2:13 pm

Hi.

What Thierry said.

if this is a significant task for you, I would consider keeping that list of fields in a custom property. You can add or subtract field names as required as you work your project, and anytime you need to:

Code: Select all

repeat for each item aField in ListOfFieldsToEmpty --this is now the custom prop name, as opposed to a variable that you manage
     put empty into field aField
end repeat
A small enhancement, but I bet it will be simpler.

Craig Newman

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: Optimizing variable declarations [SOLVED]

Post by atout66 » Fri Apr 04, 2014 2:37 pm

Really good idea Craig, I'll do that instead of to reinvent the wheal :wink:
Discovering LiveCode Community 6.5.2.

Post Reply