variable names in other variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
variable names in other variables
Sorry, I saw the answer to this or a stack here somewhere and now cannot find it.
How can I get the value of say a property whose name is in a variable, as in:
put "backcolor" into tString
answer tString with "OK"
This returns "backcolor", but what I want is it to return the backcolor property value, like "white" or "#FFFFFF".
Thanks, Walt
How can I get the value of say a property whose name is in a variable, as in:
put "backcolor" into tString
answer tString with "OK"
This returns "backcolor", but what I want is it to return the backcolor property value, like "white" or "#FFFFFF".
Thanks, Walt
Walt Brown
Omnis traductor traditor
Omnis traductor traditor
Walt,
Let's say it's a field you're interested in...
If there is no background color set, the answer box will be completely blank. If there is a color, you'll get the RGB values for the color.
Of course, you don't need the intervening variable to get the values...
Cheers,
Mark P.
Let's say it's a field you're interested in...
Code: Select all
on mouseUp
put the backgroundcolor of field 1 into tString
answer tString
end mouseUp
Of course, you don't need the intervening variable to get the values...
Code: Select all
on mouseUp
answer the backgroundcolor of field 1
end mouseUp
Mark P.
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
The do command and the value function can be used to dynamically execute commands or evaluate expressions.
So in your case it could be something like:
The merge function can also save some time and make assembling such dynamic expressions and command a lot mpore readable:
For some examples of what you can accomplish using the merge function, read these newsletter articles:
Jan Schenkel.
Code: Select all
on mouseUp
-- example of value function
put 9 into x
put "sqrt(x)" into y
answer value(y)
-- example of do command
put "answer value(y)" into z
do z
end mouseUp
Code: Select all
on mouseUp
put "backColor" into tPropertyName
put ("answer the " & tPropertyName & " of me") into tCommand
do tCommand
end mouseUp
Code: Select all
on mouseUp
put "backColor" into tPropertyName
do merge("answer the [[tPropertyName]] of me")
end mouseUp
- The Power of Merge (revUp | Issue 55 | August 18th, 2008)
- The Word of Merge - part 1 (revUp | Issue 61 | November 20th, 2008)
- The Word of Merge - part 2 (revUp | Issue 62 | December 22nd, 2008)
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Just a word about "the Power of Merge" - these are a series of incredibly useful articles which will help you get to grips with the concept of streamlining the dynamic code replacement. Very good stuff - only the online newsletter page has rendered the html entity " as a literal in the code boxes, and not applied the view as a " character.
This makes it a little confusing as Jan mentions that one of the advantages is to make the code more readable - but the rendering of " as " in the newsletter page actually makes it seem worse. Please don't get confused by this - it's not bad writing or confusing information from Jan, if you replace " with " then it will all become a lot clearer.
This makes it a little confusing as Jan mentions that one of the advantages is to make the code more readable - but the rendering of " as " in the newsletter page actually makes it seem worse. Please don't get confused by this - it's not bad writing or confusing information from Jan, if you replace " with " then it will all become a lot clearer.
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Wrt the " in the article: according to Heather, it was a deficiency in the code-to-html converter they used for tyhat article; but as this is in the process of conversion to a CMS, it should be rectified eventually.
Jan Schenkel.
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com