cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

Global Variables overwritten in a loop

Hello,

I create windows in a loop following columns. For example, in the JSL example below, I create a window with the distribution and a button that temporarily hides the window for each column (Age, Weight). The problem is that as my loop progresses, my object variables are overwritten by the last window.

For example, in the age window generated by the example, clicking on the button is supposed to temporarily hide the Age window, but in reality it hides Weight because it has been overwritten.

Is it possible to do a names default to here or something like that so that each window has its own independent space without having to change the name of the variables for each window every time? Because I have a lot of them...

 

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
lstCols = {"age", "weight"};

For Each( {value, index}, lstCols, 

	colref = Column( value );
	
	window = New Window( "Window - " || value, 
		
		V List Box(
			distribution = dt << Distribution( Column( colref ) ), 
			
			Button Box( "Hide",
				window << show window( 0 );
				Wait( 2 );
				window << show window( 1 );
			)
		);

	);
);

 

 

1 REPLY 1
jthi
Super User

Re: Global Variables overwritten in a loop

You can use window scope

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
lstCols = {"age", "weight"};

nws = {};

For Each({value, index}, lstCols, 
	colref = Column(value);
	
	nw = New Window("Window - " || value, 
		V List Box(
			window:dist = dt << Distribution(Column(colref)), 	
			Button Box("Hide",
				window:dist << show window(0);
				Wait(2);
				window:dist << show window(1);
			)
		);
	);
	Insert Into(nws, nw);
);

For Each({nw}, nws,
	Show(nw:dist << Get Window Title)
);

You could also evaluate the reference to the button script/function or use slightly more complicated function within the button to take scoping into account.

-Jarmo

Recommended Articles