cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
kayne
Level II

Dialog Popup selecting column name

Hi there, I'm trying to come up with a script where the user inputs the column name in the dialog popup and the script

1. subsets the rows with data under the column name and

2. creates a new column that performs some simple formula with the column name that was input.

I do not know how to do it so I hardcoded the column name below. How can I replace the :XX01 such that no mater what the user enters at the dialog pop up it will work. I have columns XX01, XX02, XX03, and so on...

popup = Dialog(

    Title( "Summary Table" ),

    "                             ",

    " Enter Softbin   XX:",

    Lineup( 6,

        "Softbin ID ",

        Soft_Bin = editnumber( 01 )

    ),

          

    Button( "Ok" ),

    Button( "Cancel" )

);

masterdt << select where (Is Missing(:XX01));

masterdt << Invert Row Selection;

sbdt = masterdt << Subset(( Selected Rows ), Output Table Name("Selected Softbin Data"));

sbdt << New Column( "Bin%", Numeric, Continuous, Format("Percent",12,2), Formula( :XX01 / :LOT_SORTED_DIES ) );

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Dialog Popup selecting column name

This will do what you want.  I converted your code to use new window instead of dialog.  Had to do a parse(eval()) for the column formula.

masterdt = New Table( "Master DT", Add Rows( 5 ),

      New Column( "XX01", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [1, 2, ., 3, 4] )

      ),

      New Column( "XX02", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [., 1, 2, ., .] )

      ),

      New Column( "XX03", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [., ., 1, 2, 3] )

      )

);

popup = New Window( "Summary Table", <<modal(),

      Text Box( "Enter Softbin XX:"),

      H List Box(

            Text Box( "Softbin ID:  " ),

            Soft_Bin = Number Edit Box( 01 ),

      ),

      hlistbox(

            Button Box( "Ok",

                  ok_flag = 1;

                  ncol = soft_bin << get;

                  if (ncol < 9,

                        selected_col = "XX0" || char(ncol);

                        ,

                        selected_col = "XX" || char(ncol);

                  )

            ),

            Button Box( "Cancel", ok_flag = 0 ),

      )

);

If( ok_flag,

      missing_rows = masterdt << get rows where( !Is Missing( as Column( masterdt, selected_col ) ) );

      If( N Rows( missing_rows ) > 0,

            masterdt << select rows( missing_rows );

            sbdt = masterdt << Subset( (Selected Rows), Output Table Name( "Selected Softbin Data" ) );

            formula_expr = Eval Insert(

                  "\[sbdt << New Column( "Bin%", Numeric, Continuous, Format( "Percent", 12, 2 ), Formula( :^selected_col^ / :LOT_SORTED_DIES ) )]\"

            );

            Parse( Eval( formula_expr ) );

      );

);

View solution in original post

5 REPLIES 5
pmroz
Super User

Re: Dialog Popup selecting column name

This will do what you want.  I converted your code to use new window instead of dialog.  Had to do a parse(eval()) for the column formula.

masterdt = New Table( "Master DT", Add Rows( 5 ),

      New Column( "XX01", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [1, 2, ., 3, 4] )

      ),

      New Column( "XX02", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [., 1, 2, ., .] )

      ),

      New Column( "XX03", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [., ., 1, 2, 3] )

      )

);

popup = New Window( "Summary Table", <<modal(),

      Text Box( "Enter Softbin XX:"),

      H List Box(

            Text Box( "Softbin ID:  " ),

            Soft_Bin = Number Edit Box( 01 ),

      ),

      hlistbox(

            Button Box( "Ok",

                  ok_flag = 1;

                  ncol = soft_bin << get;

                  if (ncol < 9,

                        selected_col = "XX0" || char(ncol);

                        ,

                        selected_col = "XX" || char(ncol);

                  )

            ),

            Button Box( "Cancel", ok_flag = 0 ),

      )

);

If( ok_flag,

      missing_rows = masterdt << get rows where( !Is Missing( as Column( masterdt, selected_col ) ) );

      If( N Rows( missing_rows ) > 0,

            masterdt << select rows( missing_rows );

            sbdt = masterdt << Subset( (Selected Rows), Output Table Name( "Selected Softbin Data" ) );

            formula_expr = Eval Insert(

                  "\[sbdt << New Column( "Bin%", Numeric, Continuous, Format( "Percent", 12, 2 ), Formula( :^selected_col^ / :LOT_SORTED_DIES ) )]\"

            );

            Parse( Eval( formula_expr ) );

      );

);

kayne
Level II

Re: Dialog Popup selecting column name

Thanks PMroz, the window is indeed useful. Everything is smooth except for the New Column portion.

I'm not sure what I did wrongly but the eval insert sentence is still not working although the expression in the log looks fine to me :/

masterdt = New Table( "Master DT", Add Rows( 5 ),

      New Column( "XX01", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [1, 2, ., 3, 4] )

      ),

      New Column( "XX02", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [., 1, 2, ., .] )

      ),

      New Column( "XX03", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [., ., 1, 2, 3] )

      ),

      New Column( "LOT_SORTED_DIES", Numeric, Continuous, Format( "Best", 12 ),

            Set Values( [10, 10, 10, 20, 30] )

      )

);

popup = New Window( "Summary Table", <<modal(),

      Text Box( "Enter Softbin XX:"),

        H List Box(

            Text Box( "Softbin ID:  " ),

            Soft_Bin = Number Edit Box( 01 ),

      ),

      hlistbox(

            Button Box( "Ok",

                  ok_flag = 1;

                  ncol = soft_bin << get;

                  if (ncol < 9,

                        selected_col = "XX0" || char(ncol);

                        ,

                        selected_col = "XX" || char(ncol);

                  )

            ),

            Button Box( "Cancel", ok_flag = 0 ),

      )

);

If( ok_flag,

      missing_rows = masterdt << get rows where( !Is Missing( as Column( masterdt, selected_col ) ) );

      If( N Rows( missing_rows ) > 0,

            masterdt << select rows( missing_rows );

            sbdt = masterdt << Subset( (Selected Rows), Output Table Name( "Selected Softbin Data" ) );

            formula_expr = Eval Insert(

                  "\[sbdt << New Column( "Bin%", Numeric, Continuous, Format( "Percent", 12, 2 ), Formula( :^selected_col^ / :LOT_SORTED_DIES ) )]\"

            );

            Parse( Eval( formula_expr ) );

      );

);

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Dialog Popup selecting column name

I think the expression will work if parsed before evaluated:

Eval( Parse( formula_expr ) );

kayne
Level II

Re: Dialog Popup selecting column name

Thanks MS! It works now =)

pmroz
Super User

Re: Dialog Popup selecting column name

Right you are MS.  Thanks for the correction.