Choose Language Hide Translation Bar
prismlink880
Community Trekker

How to subset based on multiple combo box selections

Hello All,

I'm trying to write a script that creates a subset based on two choices in a dynamic combo box. It seems like the dialog portion is good since my variables are being saved as I select them, but the actual generation of the subset is not working.

/* temporarily remove open database portion */

clearGlobals():

ER_Temp = Open( "C:\Users\Kilik\Desktop\Tbl_RIE_ERS.jmp" );

/* Extract a list of unique films in set "a" and unique tools in set "b"*/

Summarize( a = By( :Film ) );

Insert Into( a, "<Select Film>", 1 );

Summarize( b = By( :Tool ) );

Insert Into( b, "<Select Tool>", 1 );

/* Create a dialog*/

New Window( "Example",

    <<Modal,

    H List Box(

        /*Creates a box from which to select the film*/

        Panel Box( "Select a Film:",

            cb1 = Combo Box(

                a,

                <<SetFunction(

                    Function( {this},

                        myFilm = this << Get Selected();

                    )

                )

            )

        ),

        /*Creates a box from which to select the tool*/

        Panel Box( "Select a Tool:",

            cb2 = Combo Box(

                b,

                <<SetFunction(

                    Function( {this},

                        myTool = this << Get Selected();

                    )

                )

            )

        ),

    )

);

//creates a subset based on both selections

ER_Temp << clearRowStates;

ER_Temp << selectWhere((:Film == myFilm)&(:Tool==myTool));

Selection = ER_Temp << Subset(output table name("selection")));

Thanks,

David

0 Kudos
2 REPLIES 2
pmroz
Super User

Re: How to subset based on multiple combo box selections

You have an extra parentheses in your subset statement.  Also, I would avoid having a variable and table have the same name.  Change it to:

Select_dt = ER_Temp << Subset(output table name("selection"), selected rows(1));

Re: How to subset based on multiple combo box selections

Hi, David.

In this example, both myFilm and myTool will be strings.  As the Select Where is written, if :Film or :Tool are numeric columns, then no rows will be selected because it is not possible for a numeric column to have a string value.  The Num() function will convert a number represented as a string (for example, "12") to a numeric value.

Another thing to consider is that it might be possible for there to be no matching values in the data for the selections made in your New Window.  The user is presented with all the unique values of :Film and the unique values of :Tool, but that does not mean that for every value of :Film every value of :Tool is represented in the data.  The Select Where() statement is only selecting rows where both conditions are true.

Hope that helps.

Wendy

Wendy