accessing a variable from a string

Using the graphical user interface to build and exercise models. Includes customizing the GUI by writing a little bit of hoc or Python
Post Reply
Gannier

accessing a variable from a string

Post by Gannier »

Hello,

is it possible (or is there a way) to access and modify a variable from a string of its name:

Code: Select all

eg :
   strdef s
   s = "INa.g"

I want to print and modify the value of the variable from s
best regards,
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: accessing a variable from a string

Post by ted »

Use sprint to construct a command string, then use execute or execute1 to execute the command string. These hoc functions are documented in the Programmer's Reference.
Gannier

Re: accessing a variable from a string

Post by Gannier »

Code: Select all

proc assign() {
	strdef sTmp
	sprint(sTmp,"%s = %s", $s1, $s2)
	execute(sTmp)
}
it works very well,
Thanks Ted
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: accessing a variable from a string

Post by ted »

Everything should work so well.
Post Reply