BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
Idk
Idk
New Contributor

Script to ask for and save user input which is used in another table

I want to create a script that asks the user for character and numerical input, which is then saved in a skeleton table and referenced by another table which uses that values for calculations - Please. I can do all the seperate tasks like create a window/table/text box/calculations but I can't make them work together.

0 Kudos
5 REPLIES 5
ian_jmp
Staff

Re: Script to ask for and save user input which is used in another table

Every UI is a little different. If you can post the JSL you already have, I'm sure someone can help straighten it out.

0 Kudos
Idk
Idk
New Contributor

Re: Script to ask for and save user input which is used in another table

Names Default To Here( 1 );

// Create the Skeleton Table
dt = New Table( "2019 Run Times",
	Add Rows( 0 ),
	New Column( "Run ID", Character, "Nominal", ),
	New Column( "Run 1", Numeric, "Continuous", ),
	New Column( "Run 2", Numeric, "Continuous", ),
	New Column( "Run 3", Numeric, "Continuous", ),
	New Column( "Run 4", Numeric, "Continuous", ),
	New Column( "Run 5", Numeric, "Continuous", ),
	New Column( "Run 6", Numeric, "Continuous", ),
	New Column( "Run 7", Numeric, "Continuous", ),
	New Column( "Run 8", Numeric, "Continuous", ),
	New Column( "Run 9", Numeric, "Continuous", ),
	New Column( "Run 10", Numeric, "Continuous", ),
	New Column( "Run 11", Numeric, "Continuous", );

);
		
// Make a UI to allow the values to be entered
cols = dt << getColumnNames( "String", Continuous, Nominal );
lub1 = Lineup Box( N Col( 1 ) );
lub2 = Lineup Box( N Col( 1 ) );
For( c = 1, c <= N Items( cols ), c++,
	lub1 << Append( Text Box( cols[c] ) );
	lub2 << Append( Number Edit Box( . ) );
);
nw = New Window( "Enter Runtime Data",
	<<onClose( makeGraph ),
	Lineup Box( N Col( 2 ), lub1, lub2 ),
	Lineup Box( N Col( 2 ), Button Box( "Add", addScript ), Button Box( "Cancel", nw << closeWindow ) )
);

// Add a new row to dt when required
addScript = Expr(
	dt << addRows( 1 );
	lastRow = N Row( dt );
	For( c = 1, c <= N Items( cols ), c++,
		Column( dt, c )[lastRow] = (lub2[c] << get);
		lub2[c] << set( . );
		);
	);
	
// Then I'm not sure how to refer to a specific value in a column.
// As there will be numerous Run IDs - So eventually, I want to 
// refer to a specific Run ID, and use it's specific values for the
// calculations in another table
0 Kudos
Highlighted
ian_jmp
Staff

Re: Script to ask for and save user input which is used in another table

It's not quite clear to me if you want two scripts (one to complete or edit the skeleton table, then one to process it), or just one (to do both). In the latter case, you will need to add an 'OK' or 'Process Table' button to the UI you already have, and in the former case you could consider using the built-on row editor (which gives a lot of functionality for free):

dt << rowEditor

Whichever you go for, processing the completed skeleton table is fairly easy: Once you know what 'Run ID' you are after (from another UI?), you can do something like:

// Get the row number when 'Run ID' has the value "10"
r = dt << getRowsWhere(:Run ID == "10");
// Get the corresponding value for 'Run 1' (and so on . . . )
run1Val = Column(dt, "Run 1")[r];

 

0 Kudos
Idk
Idk
New Contributor

Re: Script to ask for and save user input which is used in another table

Ian - Say you fit a model and save its parameters in a column - is there a way that you can write a script that will save that parameters in a separate table - Because I want to use those values to create a new formula?? I would appreciate your input. The idea is to not have to open the model fit equation and them manually type in the parameters into a column.

0 Kudos
ian_jmp
Staff

Re: Script to ask for and save user input which is used in another table

This feels like a different question, and the answer depends on the details. This script may give you some ideas, though:

NamesDefaultToHere(1);

// Get some data
dt = Open("$SAMPLE_DATA/Big Class.jmp");

// Fit model dialog
fmd = dt << Fit Model(
					Y( :height ),
					Effects( :weight ),
					Personality( "Standard Least Squares" ),
					Run
					);

// Run the model
fmo = fmd << Run();

// Save the prediction formula to a new column, 'nc'
nc = fmo << SaveColumns(Prediction Formula(1));

// Get the estimates parameters into a new table
est = fmo << getEstimates;
dt2 = asTable(Transpose(est), << columnNames({"Intercept", "Slope"}));
dt2 << setName("Parameter Estimates");