In fact my concern is that I want to open 2 different data sets and use data from the first one, and then to switch to the next one.
I used the "Current Data Table" function before performing the subset.
A first part of the code is to load the "CL and Spec" data set, open a text box, to subset a row of the "CL and Spec" data set and store the parameters "LSL" and "USL" in the LSL and USL variables. Then the "CL and Spec" data set is not used any more.
Names Default to Here( 1 );
dt2 = Data Table( "CL and Spec" );
// get unique values from the strength column
levels = Associative Array( dt2:product ) << Get Keys;
// construct a window containing checkboxes
continue = 0;
New Window( "Selection",
<<Modal
,
<<On Validate(
continue = 1;
selected = cb << Get Selected;
1
)
,
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
V List Box(
Text Box( "Select values:" ),
cb = Check Box( levels ),
Spacer Box( size( 0, 20 ) )
)
)
);
If( !continue, Stop() ); //user aborted
If( N Items( selected ) == 0, Stop() );
//do the subset
rows = dt2 << Get Rows Where( Contains( As Constant( selected ), :Product ) );
dt = dt2 << Subset( Rows( rows ), All Columns, Not Linked );
// Define the control and specification limits
LSL = dt2:LSL[1];
USL = dt2:USL[1];
Then the second part of the code is to load the "Data set" data set, open a text box, and to subset rows of the "Data set" data set.
dt = Data Table( "Data Set" );
Current Data Table( dt );
// get unique values from the strength column
Summarize( dt, levels = by( :Strength ) );
// construct a window containing checkboxes
New Window( "Selection",
modal,
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
V List Box(
Text Box( "Select values:" ),
here:cb = Check Box( levels ),
Spacer Box( size( 0, 20 ) ),
Button Box( "Create Subset", doSubset() )
)
)
);
// define function to perform when button is cliccked
doSubset = Function( {},
{default local},
dt = Data Table( "Data Set" );
Current Data Table( dt );
dt << clear select;
// get user selections
selected = here:cb << get selected;
// iterate over each of the selected values
// and select the associated rows
For( i = 1, i <= N Items( selected ), i++,
rows = dt << select where( :Strength == selected[i], current selection( "extend" ) )
);
// create a subset table
dt << subset( selected rows( 1 ), selected columns only( 0 ) );
dt << clear select;
);
However, the second data is not loaded or there no subsets of the rows...
Thank you very much for your help!