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 » Fri Apr 03, 2015 10:44 pm

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: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Variable that holds the name of another variable

Post by Klaus » Fri Apr 03, 2015 11:28 pm

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 » Fri Apr 03, 2015 11:43 pm

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: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Variable that holds the name of another variable

Post by SparkOut » Sat Apr 04, 2015 12:44 am

Don't, instead use value(theVariable)

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

Re: Variable that holds the name of another variable

Post by FourthWorld » Sat Apr 04, 2015 12:46 am

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: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Variable that holds the name of another variable

Post by SparkOut » Sat Apr 04, 2015 12:17 pm

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