I know I've asked this before, but can't recall the answer.
If I have a local variable that contains a string which is the name of another variable, how do I get at the contents of the inner variable?
put 5 into variable1
put "variable1" into variable2
I want to get "5" from variable2. I tried value(variable2), but that of course gives me "variable1", unless it is a system global preceded with a dollar sign, as in:
put "$APPDATA" into variable2
value(variable2) returns "C:\Users\Walt\AppData\Roaming".
Thanks. I know this is a "Well dur" question, I'm just drawing a blank.
Variable names in variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Variable names in variables
Walt Brown
Omnis traductor traditor
Omnis traductor traditor
Re: Variable names in variables
Hi Walt,
although holding variable names in other variables is not really recommended unless avoidably,
you can make this via a DO statement!
...
put 5 into variable1
put "variable1" into variable2
do ("put" && variable2 && "into variable3")
put variable3
## Will put 5 into variable3
...
A bit cumbersome, but works
Best
Klaus
although holding variable names in other variables is not really recommended unless avoidably,
you can make this via a DO statement!
...
put 5 into variable1
put "variable1" into variable2
do ("put" && variable2 && "into variable3")
put variable3
## Will put 5 into variable3
...
A bit cumbersome, but works
Best
Klaus
Re: Variable names in variables
Thanks. I had blanked on the "do" statement.
Walt
Walt
Walt Brown
Omnis traductor traditor
Omnis traductor traditor
-
- VIP Livecode Opensource Backer
- Posts: 7239
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Variable names in variables
I don't think you need "do". This works for me:
on testvar
put 5 into var1
put var1 into var2
put var2
end testvar
Leave off the quotes and the value is used instead of the variable name.
on testvar
put 5 into var1
put var1 into var2
put var2
end testvar
Leave off the quotes and the value is used instead of the variable name.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Variable names in variables
Thanks Jacque. I'm not just transfering contents between two variables though, I want to send the name of the variable to another script for parsing.
Walt Brown
Omnis traductor traditor
Omnis traductor traditor