Subscribe Bookmark RSS Feed

Dialog Popup selecting column name

kayne

Community Trekker

Joined:

Jan 20, 2016

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 ) );

5 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

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

Community Trekker

Joined:

Jan 20, 2016

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

Joined:

Jun 23, 2011

I think the expression will work if parsed before evaluated:

Eval( Parse( formula_expr ) );

kayne

Community Trekker

Joined:

Jan 20, 2016

Thanks MS! It works now =)

pmroz

Super User

Joined:

Jun 23, 2011

Right you are MS.  Thanks for the correction.