cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

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

How to get reference to a table within "On Close" in that table?

Hi!

 

I need some help with getting a reference to the table within On Close statement of that said table.

I have a simple script: GUI with "Open" button, that opens a data table, and a combo box with list of tables.

I also keep track of the tables in an associative array with table names as keys and table references as values.

I have a couple of legacy namespaces that I have to maintain in this script. In order to remove table from the the combo box I use this Eval(Eval Expr(Expr())) trick in OnClose statement. However, this trick doesn't work with removing table from Associative Array.

There is another trick with Function({this}, _dt = ((this << Child) << Get Data Table)). It works correctly with getting the reference to data table, but stops working when I place it within Eval(Eval Expr(Expr()))).

I tried to get the reference to the table separately, but looks like I don't know how Function({this}, <script>) works. How do I assign a result of this function to a variable?

 

Anyways, here's the latest iteration of my script, please help me tweak it to make it work.

Eventually, I will need to handle data table manual name changes somehow and reflect it in the combo box.

Names Default To Here( 1 );

data = New Namespace(
	"DataTables"
);
gui = New Namespace(
	"GUI"
);

data:tablesListAA = [=> ];
gui:guiWindow = Expr(
	Border Box( Left( 10 ), Right( 10 ), Top( 10 ), Bottom( 10 ), Sides( 15 ),
		V List Box(
			gui:cb = Combo Box(
				{},
				selection = gui:cb << GetSelected();
				Print( "Selected: " || selection );
				Current Data Table( data:tablesListAA[selection] );
				Print( "Current Data Table: " || (Current Data Table() << Get Name) );
			), 
	
			Button Box( "Add Table",
				filePath = Pick File(
					"Select JMP File",
					"$SAMPLE_DATA",
					{"JMP Files|jmp;jsl;jrn", "All Files|*"},
					1,
					0,
					"newJmpFile.jmp"
				);
				dt = Open( filePath );
				Eval(
					Eval Expr(
						dt << On Close(
							getTable = Function( {this},
										_table = ((this << Child) << Get Data Table);
										Return(_table);
									);
							_table = getTable(this);
							Local( {data = Namespace( Expr( data << Get Name ) ), gui = Namespace( Expr( gui << Get Name ) ), _table = Expr(_table)},
								Try(
										_tableName = _table << Get Name;
										Print("Trying to remove: "||_tableName);
										Remove From( data:tablesListAA, _tableName );
										gui:cb << Set Items( data:tablesListAA << Get Keys );
									
								)
							)
						)
					)
				);
				

				dtName = dt << Get Name();
				Insert Into( data:tablesListAA, dtName, dt );
				gui:cb << Set Items( data:tablesListAA << Get Keys );
			
			)

		)
	)
	
);

nw = New Window( "Test table selection", gui:guiWindow );

 

 

2 REPLIES 2
jthi
Super User

Re: How to get reference to a table within "On Close" in that table?

Usually I just evaluate the table name/reference to the On Close. You can also use <<On Close(Function({this})) and this will be reference to the data table window (script index has example of this). 

View more...
Names Default To Here(1);

data = New Namespace(
	"DataTables"
);
gui = New Namespace(
	"GUI"
);

data:tablesListAA = [=> ];
gui:guiWindow = Expr(
	Border Box(Left(10), Right(10), Top(10), Bottom(10), Sides(15),
		V List Box(
			gui:cb = Combo Box(
				{},
				selection = gui:cb << GetSelected();
				Print("Selected: " || selection);
				Current Data Table(data:tablesListAA[selection]);
				Print("Current Data Table: " || (Current Data Table() << Get Name));
			), 
	
			Button Box("Add Table",
				filePath = Pick File("Select JMP File", "$SAMPLE_DATA", {"JMP Files|jmp;jsl;jrn", "All Files|*"}, 1, 0, "newJmpFile.jmp");
				dt = Open(filePath);
				Eval(
					Eval Expr(
						dt << On Close(
							tb = Expr(dt);
							_tableName = tb << get name;
							Print("Trying to remove: " || _tableName);
						)
					)
				);
				
				dtName = dt << Get Name();
				Insert Into(data:tablesListAA, dtName, dt);
				gui:cb << Set Items(data:tablesListAA << Get Keys);
			
			)

		)
	)
);

nw = New Window("Test table selection", gui:guiWindow);

You might also consider using Subscribe To Data Table List() to keep track of the tables. I have used that to build something very similar to the table list you see for example on top of JMP's script editor and it is able to handle namechanges/table closures/opens (it is more complicated to build and does have its issues).

-Jarmo
miguello
Level VII

Re: How to get reference to a table within "On Close" in that table?

For some reason I decided that baking in table into Eval(Eval Expr(Excpr))) was wrong for this use case. LEt me try to re-write it again.

Recommended Articles