Choose Language Hide Translation Bar
david707
Community Trekker

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.

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
cwillden
Super User

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 ms
Super User

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).

 

Highlighted
david707
Community Trekker

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 ) ) )]
0 Kudos
cwillden
Super User

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

akopel
Community Member

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))
		)
	)
));

 

 

0 Kudos