Subscribe Bookmark RSS Feed

Creating variables at runtime

tom_abramov

Community Trekker

Joined:

Oct 13, 2015

Hello,

Is there way to create variables at runtime (before running the app I don't know how many variables I need and their types)?

The solution I am working on:

1.User will choose some jmp/excel data table

2.The user will choose columns to use for filtering the table (Unknown amount and names)

3.The app will create list box or radio box for each choosen column and fill it with distinct values of that column

4.After user selects values for filtering, the app runs filtering and return filtered table

So, I need to create variables at runtime for each listbox with meaninful name if possible.

Thank you,

Tom.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

JSL will definatly allow you to create your own version of the Data Filter, and you will be able to present it in whatever form you believe is best for your environment.  I will tell you that all of the exception processing you will need to build in, will make the task pretty complex.  Below is a very crude script, that will give you an example of creating variables in an environment where the user can select the table and the columns within the table to process.  I chose to use the sample data table called "Big Class", but any table would work with the code. The lists created called "nameList", "handleList" and CNTList save the columns selected, and the pointer to the list boxes generated, and the final one is the number that will allow for the retireving of all of the info when a selection is chosen in one of the generated list boxes.  Now, I will clearly acknowledge that this is just one of the possible directions one could use to create the display that you want.  I will also restate, that lots of exception code, dealing with things like, removing a selected column to be filtered on, how to handle numeric filters, are the selections to be "And" or "Or" in their comparisons.......all items that need to be dealt with.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
Current Data Table( dt );

CNT = 0;

// Create lists to handle processing
nameList = {};
handleList = {};
CNTList = {};

// Create the new window
nw = New Window( "Example",
	V List Box(
		Text Box( "Data Table Columns" ),
		Spacer Box( size( 0, 10 ) ),
		clb = Col List Box(
			dt << get name,
			all,
			max selected( 1 ),
			Sel = clb << get selected;
			If( N Items( Sel ) > 0,
				CNT++;
				Insert Into( nameList, Sel[1] );
				Eval( Parse( "summarize(dt,bygp=by(:" || Char( Sel[1] ) || "))" ) );
				lb = List Box( bygp, Eval( Parse( "SelectionChoice=" || Char( CNT ) || ";" ) ) );
				Insert Into( handleList, lb );
				Insert Into( CNTList, CNT );
				HLB << append( lb );
			);
		),
		HLB = H List Box()
	)
);
Jim
3 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

You can use the builtin "Data Filter" to do what you want, without having to write any code.  Just open the desired data table and then go to the pull down menu

     Rows==>Data Filter

Then any or all columns can be selected to be filtered.

Finally, when the filters have been selected and their values chosen, the new subsetted data table can be created by going to the red triangle and selecting "Show Subset".

 

This action can also be scripted with the below code:

Names Default To Here( 1 );

// Open the desired file
path=pick file();
dt=open(path);

// Get all of the columns in the data table
colList = dt << get column names();

// Build the code required to open a Data Filter
// That has all columns available for filtering
TheExpr =
"dt << Data Filter(
	Location( {59, 59} ),
	Auto clear( 0 ),
	Mode( Show( 1 ), Include( 1 ) ),
	Add Filter( columns(";
	
TheExpr = TheExpr || ":" || colList[1];

For( i = 2, i <= N Items( colList ), i++,
	TheExpr = TheExpr || ", :" || colList[i]
);

TheExpr = TheExpr || ") ) );";

// Execute the code that was built
Eval( Parse( TheExpr ) );
Jim
tom_abramov

Community Trekker

Joined:

Oct 13, 2015

Thank you Jim.

I would like to develope my own GUI with Listboxes and Radioboxes - without using Data Filter option.

The user will be able to control which columns to use for filtering - I will let him to manage column names within "User Properties" jsl.

For example desiredColumnsList = {"ColumnA", "ColumnD"} - will be modified by user.

Then, for each column he chooses, I will create List box for filtering.

Some suggestions for that way?

Thank again.

Tom.

 

txnelson

Super User

Joined:

Jun 22, 2012

Solution

JSL will definatly allow you to create your own version of the Data Filter, and you will be able to present it in whatever form you believe is best for your environment.  I will tell you that all of the exception processing you will need to build in, will make the task pretty complex.  Below is a very crude script, that will give you an example of creating variables in an environment where the user can select the table and the columns within the table to process.  I chose to use the sample data table called "Big Class", but any table would work with the code. The lists created called "nameList", "handleList" and CNTList save the columns selected, and the pointer to the list boxes generated, and the final one is the number that will allow for the retireving of all of the info when a selection is chosen in one of the generated list boxes.  Now, I will clearly acknowledge that this is just one of the possible directions one could use to create the display that you want.  I will also restate, that lots of exception code, dealing with things like, removing a selected column to be filtered on, how to handle numeric filters, are the selections to be "And" or "Or" in their comparisons.......all items that need to be dealt with.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
Current Data Table( dt );

CNT = 0;

// Create lists to handle processing
nameList = {};
handleList = {};
CNTList = {};

// Create the new window
nw = New Window( "Example",
	V List Box(
		Text Box( "Data Table Columns" ),
		Spacer Box( size( 0, 10 ) ),
		clb = Col List Box(
			dt << get name,
			all,
			max selected( 1 ),
			Sel = clb << get selected;
			If( N Items( Sel ) > 0,
				CNT++;
				Insert Into( nameList, Sel[1] );
				Eval( Parse( "summarize(dt,bygp=by(:" || Char( Sel[1] ) || "))" ) );
				lb = List Box( bygp, Eval( Parse( "SelectionChoice=" || Char( CNT ) || ";" ) ) );
				Insert Into( handleList, lb );
				Insert Into( CNTList, CNT );
				HLB << append( lb );
			);
		),
		HLB = H List Box()
	)
);
Jim