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

Input box variable

Hi,

I want to build something like below:

1. Build a UI asking a user to "Input BIN# to analyze?"  put this value in BIN_num variable name,        ( bin number are numeric values in BIN_NO column along with other columns (machine/hardwares/ect) in my dt)

2. Use BIN_num as filter value or row selection value to select rows from BIN_NO column

3. Subset the selected rows into separate table to start analysis.

jerryspilTC
1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: Input box variable

If column BIN_NO is numeric, you might need the num() function.

dt  <<  select where( dt:BIN_NO == num( theBinNumber ) );

BTW, I agree with Jim.  You can get a script to work by using one supplied on the blog page, but soon you will be asked to make changes, especially to make it robust. For example, the script below should also include

  • a check for the data type of BIN_NO
  • handle the case if BIN_NO could have empty values.
  • check the number of rows in _idx, to determine if enough rows to do the analysis etc.

 

Here is an alternative

Names Default to Here(1);

dt = current data table();

//create a list of available bins
validbins = Associative Array(:BIN_NO) << get keys; 
BIN_num = empty();
minrows = 1;
rslt = New Window("User Selection", <<Modal, <<Return Result,
	HListBox(
		Panel Box("Enter the Bin number to analyze",
			Lineup Box(
				2,
				nb = Number Edit Box( 0 , <<Set Increment(1), <<Set Show Spin Box(1)),
			) //end 1st lineup box
		),
		Panel Box("Action",
			Lineup Box(ncol(1), 
			  ok_bb= ButtonBox("OK"),
			  cncl_bb=ButtonBox("Cancel"), 
			)// end 2nd lineup box
		)
	)
);
//don't run if empty
if(rslt["Button"]==-1, BIN_num = empty(); Throw());

BIN_num = rslt["nb"];

If (IsMissing(BIN_num) | !Contains(validbins, BIN_num),
   Caption( char(BIN_num)||" is not a valid bin number, aborting");
   wait(2);
   Caption(remove);
   Throw()  
 );

show(BIN_num);

_idx = dt << get rows where(dt:BIN_NO == BIN_num);

If(nrow(_idx) >0,
subdt = dt << Subset(Rows(_idx), OutputTableName (dt<<get name || " - BIN " ||char(BIN_num) ))
);

 

 

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Input box variable

Here is a starting point for what you want.  Make sure you take time to read the Scripting Guide

     Help==>Books==>"Scripting Guide

It will give you the background on how to proceed

Names Default To Here( 1 );
dt = Current Data Table();

nw = New Window( "Input",
	H List Box( Text Box( "Input bin number " ), binnum = Text Edit Box() ),
	Button Box( "OK",
		theBinNumber = binnum << get text;
		dt << select where( dt:BIN_NO == theBinNumber );
		dtSubset = dt << subset( selected columns( 0 ), selected rows( 1 ) );
		nw << close window;
	)
);
Jim
gzmorgan0
Super User (Alumni)

Re: Input box variable

If column BIN_NO is numeric, you might need the num() function.

dt  <<  select where( dt:BIN_NO == num( theBinNumber ) );

BTW, I agree with Jim.  You can get a script to work by using one supplied on the blog page, but soon you will be asked to make changes, especially to make it robust. For example, the script below should also include

  • a check for the data type of BIN_NO
  • handle the case if BIN_NO could have empty values.
  • check the number of rows in _idx, to determine if enough rows to do the analysis etc.

 

Here is an alternative

Names Default to Here(1);

dt = current data table();

//create a list of available bins
validbins = Associative Array(:BIN_NO) << get keys; 
BIN_num = empty();
minrows = 1;
rslt = New Window("User Selection", <<Modal, <<Return Result,
	HListBox(
		Panel Box("Enter the Bin number to analyze",
			Lineup Box(
				2,
				nb = Number Edit Box( 0 , <<Set Increment(1), <<Set Show Spin Box(1)),
			) //end 1st lineup box
		),
		Panel Box("Action",
			Lineup Box(ncol(1), 
			  ok_bb= ButtonBox("OK"),
			  cncl_bb=ButtonBox("Cancel"), 
			)// end 2nd lineup box
		)
	)
);
//don't run if empty
if(rslt["Button"]==-1, BIN_num = empty(); Throw());

BIN_num = rslt["nb"];

If (IsMissing(BIN_num) | !Contains(validbins, BIN_num),
   Caption( char(BIN_num)||" is not a valid bin number, aborting");
   wait(2);
   Caption(remove);
   Throw()  
 );

show(BIN_num);

_idx = dt << get rows where(dt:BIN_NO == BIN_num);

If(nrow(_idx) >0,
subdt = dt << Subset(Rows(_idx), OutputTableName (dt<<get name || " - BIN " ||char(BIN_num) ))
);

 

 

jerryspilTC
Level III

Re: Input box variable

Hi gzmorgan, yes the BIN_NO contains numeric.

I tried your alternative and it works, i have just encountered UI insanity as attached..

The input box shows ######## and have very small space for input..

Thanks Jim & you for prompt replies always....

jerryspilTC