32_en-US
Scripting: How to get a Name object from a quoted string?Assume I have the name of a table variable as a quoted string in a run-time variable. How do I get the table variable Name object from that?
I had this same issue with table columns which I was able to work around by getting a list of table Column Names and iterating through them until I found a Name object that matched the string. Unfortunately there doesn't appear to be a function that returns table variables so this method doesn't work.
Background:
The purpose of this is to have a reusable library that can embed formulas in columns. Since the reuse code doesn't know the Table Variable Names or Column Names, I need to pass them to my functions as string parameters. However, if I use the string variable when building the formula the result is a quoted string instead of a reference to the column or table variable.Re: Scripting: How to get a Name object from a quoted string?You can get the table variable's value from the string with
x = Current Data Table() << Get Table Variable( "teacher" );
And you can get a column's value with
x = column("height")[ 1 ];
Expressions can be used for more complicated meta-programming (JSL that manipulates JSL), but since you're starting with a string it may be better to use Parse() and Eval(). For example, the following takes a function name string and treats it as a function name.
s = "sqrt"; x = Eval( Parse( s || "(2)" ));Re: Scripting: How to get a Name object from a quoted string?Parse() is the command I needed. If only I had known about it a week ago! 
Thanks!
EDIT: I spoke a bit too soon. Parse() won't work if the table variable name contains parentheses. (For example, "Width (mm)") I'll have to think about this a bit more...
Message was edited by: DaveSRe: Scripting: How to get a Name object from a quoted string?I figured out something that works:
-----------------------------Script Start-----------------------------
Clear Globals();
Clear Log();
MyParse = Function(
{sName}, {Default Local},
ex = "Name(xxx)";
newStr = "\!"" || sName || "\!"";
retVal = Munger(ex, 0, "xxx", newStr);
retVal = Parse(retVal);
);
str = "Width (mm)";
name = MyParse(str);
show(name);
-----------------------------Script End-----------------------------
Obviously this is restricted to parsing those strings that are names. Thanks for the help!
Comments
There are no comments yet