passing in a variable name

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
neomodus
Posts: 18
Joined: Fri Apr 13, 2012 10:27 pm

passing in a variable name

Post by neomodus » Fri May 06, 2016 3:48 pm

Hi
I have variables in my code
H1[mcount]
H2[mcount]
H3[mcount]
the 1,2,3 is set using a counter
How do I programmatically pass the name of H1, H2 and H3 as say a variable myvar
so my code would appear
myvar[mcount] where myvar is set to H1 , H2 or H3
I have tried
put 1 into Fcount
put H & Fcount into myvar
when I use
answer myvar[mcount] it return the right value but if I use
answer H1[mcount] it returns empty
thx

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10044
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: passing in a variable name

Post by FourthWorld » Fri May 06, 2016 3:56 pm

Whenever you have a number of variables whose names can't be known in advance it's a good case for arrays. Since you're already using arrays, it's even easier, just add another level to it, e.g.:

Code: Select all

put "H1" into tFirstLevelKey
put "mcount" into tSecondLevelKey
put "SomeValue" into tArray[ tFirstLevelKey][tSecondLevelKey]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply