Select table, then columnsHi, I am new using JMP and JSL and I am having trouble creating a script that selects a table, then 2 columns and then do something with that.
Here is an example
Names Default to Here( 1 );
// Make list of current tables
dtNames = {};
For(t=1, t<=NTable(), t++,
InsertInto(dtNames, DataTable(t) << getName);
);
// Select the table
nw = New Window("Test", <<MODAL> 0,
Print("Table selected: "||dtName[1]),
Print("No table selected")
)
);
/* Here I tried several options like
current data table (dt);
dt << get data table;
and other but I cannot find what fits well */
xvar = .;
yvar = .;
win = New Window( "Compared Values",
<<MODAL></MODAL></MODAL>In this example I am trying a simple script where I can select one of the already open tables, select 2 columns, and do a simple plot. However I cannot manage to make the program to recognise the specific table that I select.
In the future I will need to interact with few tables at the same time and select different columns from different tables to obtain my results. I thought that this script would be an easy start. I would be very thankful if somebody could also provide me with a short explanation on why I cannot select the table that I'm choosing in the first box, or how to improve it, together with the solution to my script.
Thanks!
Automation and ScriptingSharing and Communicating ResultsRe: Select table, then columnsI suggest you read about modal windows in the Scripting Guide. Honestly, I suggest that you read the entire Scripting Guide.
Help==>JMP Documentation Library
Re: Select table, then columnsThanks a lot, your examples clarify most of my questions. My main problem was how to point at the table to make my code work, now that I see all this different options is very clear where my errors were.
One more thing, when you say "Modal windows have some default actions with OK and Cancel buttons", what do you recomend me to learn more about it? I have the scripting guide but I didn't read about it, do you think I can find it there? Or do you suggest some other source?
Thanks!
Re: Select table, then columnsHi,
I found additional issues with your original script that I think I have resolved (e.g. incorrect reference to the data table in your Col List Box)
Here is my solution that still may be a bit clunky from a coding perspective:
Names Default to Here( 1 );
show (dt);
// Make list of current tables
dtNames = {};
For(t=1, t<=NTable(), t++,
InsertInto(dtNames, DataTable(t) << getName);
);
// Select the table
nw = New Window("Test", <<MODAL> require the user to select two variables before clicking OK
Text Box( " Select test values. " ),
H List Box(
Text Box( "Select Variable " ),
x = Col List Box(
Data Table (dtxt), // data table reference > UPDATED the call to selected data table
all, // display all columns from the data table
xvar = (x << Get Selected)[1];
// get the name of the selected column before the window closes
Show( xvar );
),
Text Box( "Select ID" ),
y = Col List Box(
Data Table (dtxt), //> UPDATED the call to selected data table
all,
yvar = (y << Get Selected)[1];
Show( yvar );
)
)
);
Data Table (dtxt) << Graph Builder( // Added specific call to the seleted data table
Show Control Panel( 0 ),
Show Legend( 0 ),
Show Title( 1 ),
Variables( X( as column (xvar) ), Y( As Column (yvar) ) ),
Elements( Points( X, Y, Legend( 6 ) ) )
);</MODAL>Re: Select table, then columnsModal windows have some default actions with OK and Cancel buttons, that can mess up the code you think is happening. I find it better to adopt to the default actions, and to make simple adjustments to my code to get what I want. Here is my modification to your table selection portion of your code to get the selected data table both set as the current data table, and also to have the variable "dt" set as the pointer to the data table.
Names Default to Here( 1 );
// Make list of current tables
dtNames = {};
For(t=1, t<=NTable(), t++,
InsertInto(dtNames, DataTable(t) << getName);
);
// Select the table
nw = New Window("Test", <<MODAL></MODAL>
@Thierry_S suggestion of using a list to solve the issue is a good one. However, I do it a little bit differently. I save the full reference to the data table in the list, not just the name.
Names Default to Here( 1 );
// Make list of current tables
dtNames = {};
For(t=1, t<=NTable(), t++,
InsertInto(dtNames, data table(DataTable(t) << getName));
);
// Select the table
nw = New Window("Test", <<MODAL></MODAL>Re: Select table, then columnsThank you very much, but it does not solve my problem. Actually I had a script like this before, and I started complicating things because I cannot manage that my Col List Box update the list of columns to the selected data table. Maybe my problem is in that part of the code?Re: Select table, then columnsHi,
It looks like you may have complicated things by creating a subscript to assign the output of dtlb to dt.
I wonder of the following variation would work better for you (no need to have the "OKScript" anymore
Names Default to Here( 1 );
// Make list of current tables
dtNames = {};
For(t=1, t<=NTable(), t++,
InsertInto(dtNames, DataTable(t) << getName);
);
// Select the table
nw = New Window("Test", <<MODAL></MODAL>