Indirect Referencing
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Indirect Referencing
Hi guys,
I'm trying to reference the contents of a variable using its name in another variable. So far its not working. Any pointers? Here is an example of what I mean.
put "x,y,z" into var1
put "var1" into varibleName
put item 1 of varibleName
What I get in the message box is var1 but what I want is x.
Thanks!!!
I'm trying to reference the contents of a variable using its name in another variable. So far its not working. Any pointers? Here is an example of what I mean.
put "x,y,z" into var1
put "var1" into varibleName
put item 1 of varibleName
What I get in the message box is var1 but what I want is x.
Thanks!!!
-
- Posts: 179
- Joined: Sat Apr 08, 2006 11:08 pm
- Location: London, UK
- Contact:
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Location: Aalst, Belgium
- Contact:
You might also be interested in the value function.
HTH,
Jan Schenkel.
Code: Select all
on mouseUp
local x,y
put 16 into x
put "sqrt(x)" into y
answer value(y) -- should display 4
end mouseUp
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Nice one Jan, you've killed two birds with one stone here. See http://forums.runrev.com/phpBB2/viewtop ... 2612#12612
Re: Indirect Referencing
var1 is a variable so it doesn't need quotes. If you add quotes to it, Rev treats it as a text string.vamp07 wrote:Hi guys,
I'm trying to reference the contents of a variable using its name in another variable. So far its not working. Any pointers? Here is an example of what I mean.
put "x,y,z" into var1
put "var1" into varibleName
put item 1 of varibleName
What I get in the message box is var1 but what I want is x.
Thanks!!!
Try:
Code: Select all
put "x,y,z" into var1
put var1 into varibleName
put item 1 of varibleName
edit: another kudo to mark. I only know about value() due to some Mark tips.
use the value function
This is the correct method to indirect reference yes?
Similar to eval in other languages.
use the value function
Code: Select all
on mouseUp
put "x,y,z" into var1
put "var1" into varibleName
put item 1 of value(varibleName)
end mouseUp
Similar to eval in other languages.
vamp07 wrote:That would work but its not really indirect referencing.var1 is a variable so it doesn't need quotes. If you add quotes to it, Rev treats it as a text string.
Try:
Last edited by sturgis on Fri Mar 27, 2009 4:22 pm, edited 1 time in total.