cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
mvanderaa1
Level IV

How to use the value of my For Each loop to generate new table scripts

I am looping over existing data table scripts and creating a duplicate of each script with some alterations.

I want to insert those table script names into the generated table scripts.

 

The output I get just inserts the word "script" in my generated table scripts instead of the actual string value in scriptList

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
scriptList = dt << Get Table Script Names;
For Each({script}, scriptList,
	If ((!Contains(scriptList, "Run "||script)),				
		dt << New Script("Run "||script,dt=Current DataTable();w=eval(dt << get table property((script)));w << set window title((script)));		
	);	
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to use the value of my For Each loop to generate new table scripts

Some expression handling combined with Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute should work. Here is one example:

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

For Each({script_name}, dt << Get Table Script Names,
	If((!Contains(script_name, "Run " || script_name)),
		script_expr = dt << Get Script(script_name);
		Eval(Substitute(
			Expr(
				dt << New Script("Run " || _script_name_,
					Local({w},
						w = _new_script_;
						w << set window title(_script_name_)
					)
				);
			),
			Expr(_script_name_), script_name,
			Expr(_new_script_), Name Expr(script_expr)
		))
	)
);
-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: How to use the value of my For Each loop to generate new table scripts

Some expression handling combined with Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute should work. Here is one example:

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

For Each({script_name}, dt << Get Table Script Names,
	If((!Contains(script_name, "Run " || script_name)),
		script_expr = dt << Get Script(script_name);
		Eval(Substitute(
			Expr(
				dt << New Script("Run " || _script_name_,
					Local({w},
						w = _new_script_;
						w << set window title(_script_name_)
					)
				);
			),
			Expr(_script_name_), script_name,
			Expr(_new_script_), Name Expr(script_expr)
		))
	)
);
-Jarmo
mvanderaa1
Level IV

Re: How to use the value of my For Each loop to generate new table scripts

thank you that is indeed working nicely

mvanderaa1
Level IV

Re: How to use the value of my For Each loop to generate new table scripts

Hi, I guess I didn't specify as such in my original question, but your solution did change the behaviour of my script since it copies the target script code into the new script. I wanted to keep the reference only to the original script. Here's the final script I'm using, maybe other people might find it useful.

 

dt = Current Data Table();
scriptList = dt << Get Table Script Names;

For Each( {script_name}, scriptList,
	If( (!Contains( script_name, "Run" ) & !Contains( scriptList, "Run " || script_name )),
		Eval(
			Substitute(
					Expr(
						dt << New Script(
							"Run " || script_name,
							dt = Current Data Table();
							w = Eval( dt << get table property( script_placeholder ) );
							w << set window title( script_placeholder );
						)
					),
				Expr(script_placeholder), Char(script_name)
			)
		)
	)
);
lala
Level VIII

Re: How to use the value of my For Each loop to generate new table scripts

JMP 14 no work.

txnelson
Super User

Re: How to use the value of my For Each loop to generate new table scripts

For Each() function is a new feature in JMP 16.

Jim