Variable that holds the name of another 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
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Variable that holds the name of another variable

Post by croivo »

This is the code:

Code: Select all

on mouseUp
   put "My Text" into myVariable77
   put ("myVariable" & "77") into variableThatHoldsTheNameOfOriginalVariable
   answer variableThatHoldsTheNameOfOriginalVariable
end mouseUp
How to make it answer "My Text" ?
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Variable that holds the name of another variable

Post by Klaus »

Hi croivo,

just DO it! :D

Code: Select all

on mouseUp
   put "My Text" into myVariable77
   put ("myVariable" & "77") into variableThatHoldsTheNameOfOriginalVariable
   DO ("answer" && variableThatHoldsTheNameOfOriginalVariable)
end mouseUp

Best

Klaus
croivo
Posts: 111
Joined: Wed Feb 26, 2014 11:02 pm

Re: Variable that holds the name of another variable

Post by croivo »

That's it :D

But... What if I have something like this

Code: Select all

put "My Text" into myVariable77
put ("myVariable" & "77") into variableThatHoldsTheNameOfOriginalVariable
put ("The content of the variable is: " & variableThatHoldsTheNameOfOriginalVariable) into myVariable
How to use 'DO' now?
SparkOut
Posts: 2984
Joined: Sun Sep 23, 2007 4:58 pm

Re: Variable that holds the name of another variable

Post by SparkOut »

Don't, instead use value(theVariable)
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Variable that holds the name of another variable

Post by FourthWorld »

What are you doing with that variable?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
SparkOut
Posts: 2984
Joined: Sun Sep 23, 2007 4:58 pm

Re: Variable that holds the name of another variable

Post by SparkOut »

See here for more detail, and a demo of how to use value()

http://forums.livecode.com/viewtopic.ph ... 31#p123699


(scroll to the bottom of the thread)
Post Reply