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
CaseyL
Level II

JSL button box: fix variables at time of button creation

My script creates a list of buttons using a for loop. each button calls a function "RepGen" which needs the button's name for an input. The button's behavior doesn't seem to be evaluated until the button is pressed though, at which time the for loop has overwritten the variable containing the button name. Is there a way to evaluate this variable at the time the button is created instead of when it is pressed? Or is there a better way to do this?

 

dtSum = dt << Summary( Group( :ColX ) );
For( i = 1, i <= N Rows( dtSum ), i++,
	varName = dtSum:ColX[i];
	obparts << append( Button Box( varName, RepGen( varName ) ) );
);
1 ACCEPTED SOLUTION

Accepted Solutions
vince_faller
Super User (Alumni)

Re: JSL button box: fix variables at time of button creation

Using Eval(EvalExpr()) or Eval(Substitute()) will let you make runtime variables static.  Check the scripting index for examples how to use them.  

 

Names Default to Here( 1 );

RepGen = function({btn_name}, 
	{DEFAULT LOCAL},
	print(btn_name);
);

vlb = Vlistbox();
btns = {"Btn 1", "Other", "Button 2 (or3)"};

for(i=1, i<=nitems(btns), i++, 
	vlb << Append(
		Eval(
			//run just this block to show that the buttons are getting evaluated at creation time
			EvalExpr(
				Buttonbox(btns[i], RepGen(Expr(btns[i])))//the expr will evaluate inside the evalexpr
			)
		)
	)
);
new window("Test", 
	vlb
);
Vince Faller - Predictum

View solution in original post

1 REPLY 1
vince_faller
Super User (Alumni)

Re: JSL button box: fix variables at time of button creation

Using Eval(EvalExpr()) or Eval(Substitute()) will let you make runtime variables static.  Check the scripting index for examples how to use them.  

 

Names Default to Here( 1 );

RepGen = function({btn_name}, 
	{DEFAULT LOCAL},
	print(btn_name);
);

vlb = Vlistbox();
btns = {"Btn 1", "Other", "Button 2 (or3)"};

for(i=1, i<=nitems(btns), i++, 
	vlb << Append(
		Eval(
			//run just this block to show that the buttons are getting evaluated at creation time
			EvalExpr(
				Buttonbox(btns[i], RepGen(Expr(btns[i])))//the expr will evaluate inside the evalexpr
			)
		)
	)
);
new window("Test", 
	vlb
);
Vince Faller - Predictum