cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
nikles
Level VI

Possible to change a single value in a string col box() list?

Hi.  I'm wondering if there's a way to update a single item in a string col box()?  For example, is there a command like:

scb = StringColBox("title", mylist);
scb << Set Item(i,  "newvalue");    //is there a cmd like this?

I have a window with a string col box, and I would like my script to update a single value.  My current method:

1. Get the entire list from the string col box

2. Modify the list

3. Write the list back to the string col box.

This works, but can be slow for large lists.  

 

The string col box() display object has both a "Set" and "Set Values" command, but both appear to set the entire list.  Perhaps there's another trick one can use to change individual items though?

 

JMP Pro 17.0.0

Mac OS Ventura 13.1

 

Thanks.

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Possible to change a single value in a string col box() list?

I don't think you can set single values in String Col Box (at least not easily).

 

Depending on your application, using Data Table Box could be an option

Names Default To Here(1);

Names Default To Here(1);
dt = New Table("BOX", 
	New Column("SCB_VALS", Character, Nominal, Values({"A","B","C"}))
	, private
);

nw = New Window("Example",
	window:dt = dt,
	dtb = Data Table Box(dt)
);
nw << On Close(function({this},
	Close(this:dt, no save);
));

wait(1);
dt[1,1] = "D";

You could also build string col box using Col Box and Text Boxes.

-Jarmo

View solution in original post

txnelson
Super User

Re: Possible to change a single value in a string col box() list?

Here is a complete example of changing single values  in a String Col Box() and in a Number Col Box()

txnelson_0-1677330831430.png

Names Default To Here( 1 );
dtData = Open( "$SAMPLE_DATA/big class.jmp", private );
dt = New Table( "hidden", private, New Column( "theRow", set values( Index( 1, N Rows( dtData ) ) ) ) );
dt << update( with( dtData ) );
Close( dtData, nosave );

numberList = As List( Column( dt, 1 ) << get values );
For Each( {value, i}, numberList, numberList[i] = Char( value ) );

nw = New Window( "Example",
	H List Box(
		myTable = Table Box(
			c0 = Number Col Box( "", Column( dt, 1 ) << get values ),
			c1 = String Col Box( Column( dt, 2 ) << get name, Column( dt, 2 ) << get values ),
			c2 = Number Col Box( Column( dt, 3 ) << get name, Column( dt, 3 ) << get values ),
			c3 = String Col Box( Column( dt, 4 ) << get name, Column( dt, 4 ) << get values ),
			c4 = Number Col Box( Column( dt, 5 ) << get name, Column( dt, 5 ) << get values ),
			c5 = Number Col Box( Column( dt, 6 ) << get name, Column( dt, 6 ) << get values )
		),
		Panel Box( "Change Values",
			H List Box(
				cb1 = Combo Box( {"Name", "Age", "Sex", "Height", "Weight"} ),
				cb2 = Combo Box( numberList ),
				teb = Text Edit Box( "", <<set width( 80 ) ),
				changeBox = Button Box( "Change Value",
					theColumn = cb1 << get text;
					theRow = Num( cb2 << get text );
					If( Contains( {"Name", "Sex"}, theColumn ),
						theValue = teb << get text,
						theValue = Num( teb << get text )
					);
					Column( dt, theColumn )[theRow] = theValue;
					newValues = dt[theRow, 0];
					myTable << delete row( theRow );
					Eval(
						Parse(
							"myTable << insert row(" || Char( theRow ) || ", " || Char( newValues ) || ");"
						)
					);
				)
			)
		)
	)
);
nw << on close( Close( dt, nosave ) );

 

Jim

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: Possible to change a single value in a string col box() list?

There are Delete Row and Insert Row options available for the Table Box, which might be able to help you.  If there is more thatan one column in the table box, it can become complex, keeping track of all of the columns in the table box

Names Default To Here( 1 );
New Window( "test", 
	tb = Table Box( 
		String Col Box( "string col", {"a", "b", "c", "d"} ) 
	) 
);
Wait( 5 );
tb << delete row( 2 );
tb << insert row( 2, {"x"} );
Jim
jthi
Super User

Re: Possible to change a single value in a string col box() list?

I don't think you can set single values in String Col Box (at least not easily).

 

Depending on your application, using Data Table Box could be an option

Names Default To Here(1);

Names Default To Here(1);
dt = New Table("BOX", 
	New Column("SCB_VALS", Character, Nominal, Values({"A","B","C"}))
	, private
);

nw = New Window("Example",
	window:dt = dt,
	dtb = Data Table Box(dt)
);
nw << On Close(function({this},
	Close(this:dt, no save);
));

wait(1);
dt[1,1] = "D";

You could also build string col box using Col Box and Text Boxes.

-Jarmo
txnelson
Super User

Re: Possible to change a single value in a string col box() list?

Here is a complete example of changing single values  in a String Col Box() and in a Number Col Box()

txnelson_0-1677330831430.png

Names Default To Here( 1 );
dtData = Open( "$SAMPLE_DATA/big class.jmp", private );
dt = New Table( "hidden", private, New Column( "theRow", set values( Index( 1, N Rows( dtData ) ) ) ) );
dt << update( with( dtData ) );
Close( dtData, nosave );

numberList = As List( Column( dt, 1 ) << get values );
For Each( {value, i}, numberList, numberList[i] = Char( value ) );

nw = New Window( "Example",
	H List Box(
		myTable = Table Box(
			c0 = Number Col Box( "", Column( dt, 1 ) << get values ),
			c1 = String Col Box( Column( dt, 2 ) << get name, Column( dt, 2 ) << get values ),
			c2 = Number Col Box( Column( dt, 3 ) << get name, Column( dt, 3 ) << get values ),
			c3 = String Col Box( Column( dt, 4 ) << get name, Column( dt, 4 ) << get values ),
			c4 = Number Col Box( Column( dt, 5 ) << get name, Column( dt, 5 ) << get values ),
			c5 = Number Col Box( Column( dt, 6 ) << get name, Column( dt, 6 ) << get values )
		),
		Panel Box( "Change Values",
			H List Box(
				cb1 = Combo Box( {"Name", "Age", "Sex", "Height", "Weight"} ),
				cb2 = Combo Box( numberList ),
				teb = Text Edit Box( "", <<set width( 80 ) ),
				changeBox = Button Box( "Change Value",
					theColumn = cb1 << get text;
					theRow = Num( cb2 << get text );
					If( Contains( {"Name", "Sex"}, theColumn ),
						theValue = teb << get text,
						theValue = Num( teb << get text )
					);
					Column( dt, theColumn )[theRow] = theValue;
					newValues = dt[theRow, 0];
					myTable << delete row( theRow );
					Eval(
						Parse(
							"myTable << insert row(" || Char( theRow ) || ", " || Char( newValues ) || ");"
						)
					);
				)
			)
		)
	)
);
nw << on close( Close( dt, nosave ) );

 

Jim
nikles
Level VI

Re: Possible to change a single value in a string col box() list?

Thanks @txnelson .  I like your idea as well.  Just goes to show there's more than one way to skin a cat.

-nikles

nikles
Level VI

Re: Possible to change a single value in a string col box() list?

Thanks @jthi.  That's cool.  I've never seen the Data Table Box() function before.  It appears that instead of writing data to display boxes, you just write it to a data table and the window updates automatically.  This opens a lot of doors for me.    Excellent.

-nikles