repeat in variable

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
vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

repeat in variable

Post by vedus » Tue Mar 31, 2015 10:02 pm

In my stack i have bellow objects..
1 group with some fields and 2 variables.
Variable 1 have the field names and variable 2 have the values i want like (name1,name2,etc)
I want to get the field name from the var 1 and pass the value from var 2 into text of field.
is that possible and how to?
my code until now

Code: Select all

repeat with x=1 to the number of flds of group "grp-A"
          add 1 to counter
          put the short name of  fld x & cr after fNames
     end repeat

     set the itemdel to comma
     put 0 into myCounter
     repeat for each line f in fNames
          repeat for each line t in tvalues

          end repeat
     end repeat

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: repeat in variable

Post by SparkOut » Tue Mar 31, 2015 10:25 pm

You have a lot of unnecessary lines to do this job

Code: Select all

repeat with x=1 to the number of flds of group "grp-A"
   put line x of tValues into field x of group "grp-A"
 end repeat
But if you want to refer to a field by resolving a variable name, you can put the name in parentheses:

put "data" into field (tFieldVar)

You might get away without the parentheses but don't leave them out. It makes things so much better for the engine.

vedus
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 153
Joined: Tue Feb 26, 2013 9:23 am

Re: repeat in variable

Post by vedus » Tue Mar 31, 2015 10:31 pm

SparkOut wrote:You have a lot of unnecessary lines to do this job

Code: Select all

repeat with x=1 to the number of flds of group "grp-A"
   put line x of tValues into field x of group "grp-A"
 end repeat
But if you want to refer to a field by resolving a variable name, you can put the name in parentheses:

put "data" into field (tFieldVar)

You might get away without the parentheses but don't leave them out. It makes things so much better for the engine.
Thank you Sparkout,i will give a try.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”