Page 1 of 1

accessing a variable from a string

Posted: Tue Mar 27, 2012 6:05 am
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,

Re: accessing a variable from a string

Posted: Tue Mar 27, 2012 5:15 pm
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.

Re: accessing a variable from a string

Posted: Wed Mar 28, 2012 5:03 am
by Gannier

Code: Select all

proc assign() {
	strdef sTmp
	sprint(sTmp,"%s = %s", $s1, $s2)
	execute(sTmp)
}
it works very well,
Thanks Ted

Re: accessing a variable from a string

Posted: Wed Mar 28, 2012 12:13 pm
by ted
Everything should work so well.