Page 1 of 1

passing in a variable name

Posted: Fri May 06, 2016 3:48 pm
by neomodus
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

Re: passing in a variable name

Posted: Fri May 06, 2016 3:56 pm
by FourthWorld
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]