cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
david707
Level III

Pass a Script Variable into a New Script

Hi,

Basically I am trying to use a for loop to imbed multiple scripts into a data table:

 

For( SV = 1, SV <= N Items( CL ), SV++,
	DT2 << New Script(
		Char(SV),
			For( x = 7, x <= N Items( ColLst ), x++,
				:Column(Char(ColLst[x])) << Hide (1);
			);
			For( w = 1, w <= N Items( Lst ), w++,
				:Column(Char(CL[SV][w])) << Hide (0);
			);
	);
);

The problem is when one of these scripts run it doesn't know what SV is. I need a way of capturing SV from the main script and setting it into the New Script. For example if I replace SV with 1 all the imbedded scripts will work as if SV == 1, so I need the For Loop to "set" SV to the correct value for that script.

 

Hopefully this makes some kind of sense.

1 ACCEPTED SOLUTION

Accepted Solutions
cwillden
Super User (Alumni)

Re: Pass a Script Variable into a New Script

Try this:

For( SV = 1, SV <= N Items( CL ), SV++,
	Eval(Parse(Eval Insert("DT2 << New Script(
		Char(SV),
			For( x = 7, x <= N Items( ColLst ), x++,
				:Column(Char(ColLst[x])) << Hide (1);
			);
			For( w = 1, w <= N Items( Lst ), w++,
				:Column(Char(CL[^SV^][w])) << Hide (0);
			);
		);"
	)));
);

 

-- Cameron Willden

View solution in original post

4 REPLIES 4
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Pass a Script Variable into a New Script

Try using Eval( Eval Expr(...Expr(SV)...)) to force pre-evaluation of SV (and CL if necessary).

 

david707
Level III

Re: Pass a Script Variable into a New Script

I tried:

For( SV = 1, SV <= N Items( CL ), SV++,
	DT2 << New Script(                                                         
		Char(SV),
			For( x = 6, x <= N Items( ColLst ), x++,
				:Column(Char(ColLst[x])) << Hide (1);
			);
			For( w = 1, w <= N Items(
					Eval(
						Eval Expr(
							Expr(
								CL[
									Eval(
										Eval Expr(
											Expr(SV)
										)
									)
								]
							)
						)
					) 
				), w++,
				:Column(
					Char(
						Eval(
							Eval Expr(
								CL[
									Eval(
										Eval Expr(
											Expr(SV)
										)
									)
								][w]
							)
						)
					)
				) << Hide (0);
			);
	);
);

The error is:

 

Subscript Range in access or evaluation of 'Subscript' , CL[/*###*/Eval( Eval Expr( Expr( SV ) ) )]
cwillden
Super User (Alumni)

Re: Pass a Script Variable into a New Script

Try this:

For( SV = 1, SV <= N Items( CL ), SV++,
	Eval(Parse(Eval Insert("DT2 << New Script(
		Char(SV),
			For( x = 7, x <= N Items( ColLst ), x++,
				:Column(Char(ColLst[x])) << Hide (1);
			);
			For( w = 1, w <= N Items( Lst ), w++,
				:Column(Char(CL[^SV^][w])) << Hide (0);
			);
		);"
	)));
);

 

-- Cameron Willden
akopel
Level I

Re: Pass a Script Variable into a New Script

In general you can use this method to pass variable into a script:

 

 

Eval (eval expr(
	dt << New script (
		"name",
		Bivariate(
			Y(expr(col_var)),
			X(expr(col_list_var))
		)
	)
));