Subscribe Bookmark RSS Feed

Send value of check box to the last row of a specified column

Onjai

Occasional Contributor

Joined:

Jul 12, 2017

The user selects a point on a chart. The script is then run where the user selects an option in a modal check box, "start" or "end".  The script copies the selected row of data to another table, dt2.  This part works fine.  I cannot seem to append the value selected in the check box into column called "position" for the same row that was just added by the concatenate statement.

 

//Modal (non-Modal) Retrieval in OK button
//Initialize
cycleList = {"start", "end"};
rb_c = 0;

New Window( "Select start/end", <<Modal, // comment out Modal and run this block
Text Box( "Please select if start of cycle or end" ),
Text Box( " " ),
H List Box(
Panel Box( "Cycle",
Lineup Box( 1,
rb_cycle = Radio Box( cycleList, <<Set( rb_g ) )
) // end LineupBox
), //end PanelBox
Panel Box( "Action",
V List Box(
ok_btn = Button Box( "OK",
rb_c = rb_cycle << Get;
wait(0);
dt2 << Go To (6);
dt2 <<go to row(nrow(dt2);
Values(rb_c));
Show(rb_c, cycleList[rb_c],
// Get Selected returns the list value
(rb_cycle << Get selected) )
), //end OK
cncl_btn = Button Box( "Cancel" )
)
)
)
);
dt = Data Table ("Big Class");
dt2 = Data Table ("BigClass2");
dt3 = dt << subset( Selected Rows( 1 ), Selected columns only( 0 ) );
dt2 << concatenate( dt3, AppendToFirstTable( 1 ) );
dt3 << Close Window;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp

Staff

Joined:

Jun 23, 2011

Solution

You can avoid the JMP 13 dependency by using a loop:

NamesDefaultToHere(1);

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

// UI
win = NewWindow("Select Cycles",
			rc = dt << Control Chart(
								Sample Size( 1 ),
								KSigma( 3 ),
								Chart Col( :height, Run Chart( Show Center Line( 0 ) ) )
							),
			PanelBox("Define Cycle",
				LineUpBox(NCol(2),
					ButtonBox("Start Cycle", startScript),
					ButtonBox("End Cysle", endScript)
					)
				)
			);

// Make a copy of 'dt' with no rows
dt2 = Eval(dt << getScript);
dt2 << deleteRows(1::NRow(dt));
dt2 << setName((dt << getName)||" - Cycles");
// Add extra columns
dt2 << NewColumn("Row", Numeric, Ordinal);
dt2 << NewColumn("Cycle", Character);

// When 'Start Cycle' is pressed - If multiple rows are selected, take the first
startScript =
Expr(
	r = dt << getSelectedRows;
	dt2 << addRows(1);
	for(c=1, c<=NCol(dt), c++, Column(dt2, c)[NRow(dt2)] = Column(dt, c)[r[1]]);
	Column(dt2, "Row")[NRow(dt2)] = r[1];
	Column(dt2, "Cycle")[NRow(dt2)] = "Start";
);

// When 'End Cycle' is pressed - If multiple rows are selected, take the first
endScript =
Expr(
	r = dt << getSelectedRows;
	dt2 << addRows(1);
	for(c=1, c<=NCol(dt), c++, Column(dt2, c)[NRow(dt2)] = Column(dt, c)[r[1]]);
	Column(dt2, "Row")[NRow(dt2)] = r[1];
	Column(dt2, "Cycle")[NRow(dt2)] = "End";
);

Regarding 'multiple rows will not be selected by the user', then, if I have understood correctly, it is certainly possible that they could . . .

4 REPLIES
ian_jmp

Staff

Joined:

Jun 23, 2011

The code didn't run for me, so I offer an alternative that you might be able to build on (requires JMP 13 because of the table subscripting):

NamesDefaultToHere(1);

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

// UI
win = NewWindow("Select Cycles",
			rc = dt << Control Chart(
								Sample Size( 1 ),
								KSigma( 3 ),
								Chart Col( :height, Run Chart( Show Center Line( 0 ) ) )
							),
			PanelBox("Define Cycle",
				LineUpBox(NCol(2),
					ButtonBox("Start Cycle", startScript),
					ButtonBox("End Cysle", endScript)
					)
				)
			);

// Make a copy of 'dt' with no rows
dt2 = Eval(dt << getScript);
dt2 << deleteRows(1::NRow(dt));
dt2 << setName((dt << getName)||" - Cycles");
// Add extra columns
dt2 << NewColumn("Row", Numeric, Ordinal);
dt2 << NewColumn("Cycle", Character);

// When 'Start Cycle' is pressed - If multiple rows are selected, take the first
startScript =
Expr(
	r = dt << getSelectedRows;
	dt2 << addRows(1);
	dt2[NRow(dt2), 1::NCol(dt)] = dt[r[1],0];
	dt2[NRow(dt2), "Row"] = r[1];
	dt2[NRow(dt2), "Cycle"] = "Start";
);

// When 'End Cycle' is pressed - If multiple rows are selected, take the first
endScript =
Expr(
	r = dt << getSelectedRows;
	dt2 << addRows(1);
	dt2[NRow(dt2), 1::NCol(dt)] = dt[r[1],0];
	dt2[NRow(dt2), "Row"] = r[1];
	dt2[NRow(dt2), "Cycle"] = "End";
);

Perhaps you had a good reason to design it the way you did, but it seems that defining a start and an end makes it more complicated and error prone than defining a range (that is, a whole cycle).

Onjai

Occasional Contributor

Joined:

Jul 12, 2017

Hi Ian,

Using JMP 11.  The user is presented with the chart from which they choose a single data point, run the script to define whether the point is the start or end of a cycle.  I need the entire row of data saved to another table with the new column "position" defining whether that row is a "start" or "end" of the cycle.  Multiple rows will not be selected by the user.  Attached is a sample "chart 2" showing weight loss against time.  The code will copy and save the row that the user selected, however, I cannot seem to trap the user's selection (start or end) and save that value to the "position" column for that row.

Cheers

 

 

 

ian_jmp

Staff

Joined:

Jun 23, 2011

Solution

You can avoid the JMP 13 dependency by using a loop:

NamesDefaultToHere(1);

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

// UI
win = NewWindow("Select Cycles",
			rc = dt << Control Chart(
								Sample Size( 1 ),
								KSigma( 3 ),
								Chart Col( :height, Run Chart( Show Center Line( 0 ) ) )
							),
			PanelBox("Define Cycle",
				LineUpBox(NCol(2),
					ButtonBox("Start Cycle", startScript),
					ButtonBox("End Cysle", endScript)
					)
				)
			);

// Make a copy of 'dt' with no rows
dt2 = Eval(dt << getScript);
dt2 << deleteRows(1::NRow(dt));
dt2 << setName((dt << getName)||" - Cycles");
// Add extra columns
dt2 << NewColumn("Row", Numeric, Ordinal);
dt2 << NewColumn("Cycle", Character);

// When 'Start Cycle' is pressed - If multiple rows are selected, take the first
startScript =
Expr(
	r = dt << getSelectedRows;
	dt2 << addRows(1);
	for(c=1, c<=NCol(dt), c++, Column(dt2, c)[NRow(dt2)] = Column(dt, c)[r[1]]);
	Column(dt2, "Row")[NRow(dt2)] = r[1];
	Column(dt2, "Cycle")[NRow(dt2)] = "Start";
);

// When 'End Cycle' is pressed - If multiple rows are selected, take the first
endScript =
Expr(
	r = dt << getSelectedRows;
	dt2 << addRows(1);
	for(c=1, c<=NCol(dt), c++, Column(dt2, c)[NRow(dt2)] = Column(dt, c)[r[1]]);
	Column(dt2, "Row")[NRow(dt2)] = r[1];
	Column(dt2, "Cycle")[NRow(dt2)] = "End";
);

Regarding 'multiple rows will not be selected by the user', then, if I have understood correctly, it is certainly possible that they could . . .

Onjai

Occasional Contributor

Joined:

Jul 12, 2017

Hi Ian,

This works fine!  Thank you very much.  The script will save hours and hours of transcribing start and end of cycle data points.

Cheers!