cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Rans
Level II

how do I Save variable values to new script

Hi, 

I'm trying to save metadata to a table, so next time I open the file I will be able to use some variables I used when I built the table. 

I understand that currently only strings can be saved as metadata to the table.

The other options I tried is to save new script to the table that will include the variables that I need.

the problem is that I don't understand how to use the "Save Script" in a way that will add the value of the variable instead of the variable name.

for example I tried this :

x = expr (a = [1,2,3]);
dt << New script ("test",char (x));

which results in a script with - char(x).

I tried any expr/eval/parse combination I could think of but non of them helped.

I just want the new script "test" to include :

a = [1,2,3]

but when I'm writing the script of course I don't know the actual value of a. 

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

Re: how do I Save variable values to new script

Hi,

 

Does this do what you're looking for?:

x = expr ("a = [1,2,3]");
eval(eval expr(dt << New script ("test",char (expr(parse(x))))));

View solution in original post

4 REPLIES 4

Re: how do I Save variable values to new script

Hi,

 

Does this do what you're looking for?:

x = expr ("a = [1,2,3]");
eval(eval expr(dt << New script ("test",char (expr(parse(x))))));
Rans
Level II

Re: how do I Save variable values to new script

Thanks for your help.

I missed the option of using "eval (eval expr(".."))"

The way I finally used it was like this  - 

a = {1,2,3};
Eval(Eval Expr(dt << New script ("test",
a = expr (a);
)));

this way the new test script now include "a = {1,2,3};", which is what I wanted.

Thanks again. 

 

ian_jmp
Staff

Re: how do I Save variable values to new script

Slightly different, not necessarily better:

NamesDefaultToHere(1);

dt = NewTable("Test");

myScript =
Expr(
	a = {1, 2, 3, 4};
	Speak(a);
	);

addScript = 
Expr(
	dt << NewScript(nTBD, sTBD)
	);

SubstituteInto(
	addScript,
	Expr(nTBD), "My Script",
	Expr(sTBD), EvalExpr(myScript)
	);

addScript;
pmroz
Super User

Re: how do I Save variable values to new script

I like to use evalinsert and eval(parse()).

dt = New Table( "Untitled 8",
	Add Rows( 2 ),
	New Column( "Column 1", Character, "Nominal", Set Values( {"a", "b"} ) )
);
a1 = "a = [1, 2, 3]";
b1 = evalinsert("\[dt << new script("test", ^a1^)]\");
eval(parse(b1));