get the value of a Variable by its name (e.g variableNames)

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
ueliweb
Posts: 118
Joined: Wed May 11, 2011 9:47 am

get the value of a Variable by its name (e.g variableNames)

Post by ueliweb » Tue Mar 13, 2012 11:30 am

Hei

is it possible to get the value if I just know its name e.g. as I get it from the variableNames() function?
And how I get the running handlers own name? (because the `me`gives me the objects name where the handler is in.

Or is there an other possibility like to get/ log the "Variable" shown under the script window?

I want log some variables at some points. And for this I write a small command that write the wished info to a logfile
The breakpoints interrupt to much and the Message Watcher shows the sequence of the messages ...
and both only works in LC dev environment...

I tried it with this code but the value is allways the name of the Variable

Code: Select all

command ShowVariablesNameAndContent
   put "Test 11" into TheTestVariable1
   put "Test 22" into TheTestVariable2
   put "Test 33" into TheTestVariable3
   
   put the variableNames into theVariableNames
   --   replace comma with return in theVariableNames
   
   repeat with x= 1 to the number of items in theVariableNames
      put item x of theVariableNames into thisVariable
      put item x of theVariableNames & ":" && thisVariable into line x of theVariableWithContent
      --      put item x of theVariableNames & ":" && value(thisVariable) into line x of theVariableWithContent
      --      put item x of theVariableNames & ":" && value("thisVariable") into line x of theVariableWithContent
   end repeat
   
   put theVariableWithContent
end ShowVariablesNameAndContent
with properties it works fine with some code like this

Code: Select all

put "SomePropName" into cAcustomPropertyName
put the cAcustomPropertyName of this stack into thePropValue
some suggestion?

thanks
ueliweb

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: get the value of a Variable by its name (e.g variableNam

Post by Mark » Tue Mar 13, 2012 12:17 pm

Hi,

Make a field with a tabstop and use the following script, e.g. in a mouseUp handler:

Code: Select all

put the variableNames into myVars
repeat for each line myVar in myVars
  do "put" && myVar && "into myValue"
  put myVar & tab & myValue & cr after myList
end repeat
put char 1 to -2 of myList into fld x
Kind regards,

If you want to know which handler called your script, then use

Code: Select all

put line -2 of the executionContexts into myHandler
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

ueliweb
Posts: 118
Joined: Wed May 11, 2011 9:47 am

Re: get the value of a Variable by its name (e.g variableNam

Post by ueliweb » Tue Mar 13, 2012 12:54 pm

Thanks Mark

really great

´Do´thats what I am was locking about to script a statemant together :-)
`executionContexts` makes other problems easier

thanks again
ueliweb

Post Reply