Subscribe Bookmark RSS Feed

Adding Expressions via a Variable

jbakri21

Community Trekker

Joined:

Jul 8, 2016

Hello JMP Community,

I am building a JSL script that allows the user to select multiple variables via checkboxes. The data is grouped via two columns "Type" and "Size". I have the first variable working so that when the user marks that check box and runs the script it creates a chart of that variable for each combination of type and size (e.g. if there are 5 types and 2 sizes I'll get 10 graphs each with its own outline box). The problem I'm running into is adding a second, third, etc variable. I am not sure how to add new charts without adding repeat outline boxes.

This is the code I have that creates the charts for the first variable.

New Window("Charts",

     Platform(dt,

          If(Checkbox1 == 1,

               Control Chart(

                    Sample Label( :Date ),

                    Phase( :Machine ),

                    KSigma( 3 ),

                    Chart Col(:Variable1, Levey Jennings( Show Control Limits( 0 ))),

                    By( :Size, :Type )

               )

          )

     )

The next line I added was this:

     Platform(dt,

          If(Checkbox2 == 1,

               Control Chart(

                    Sample Label( :Date ),

                    Phase( :Machine ),

                    KSigma( 3 ),

                    Chart Col(:Variable2, Levey Jennings( Show Control Limits( 0 ))),

                    By( :Size, :Type )

               )

          )

     )

);

Unfortunately this doubled the number of outline boxes I have rather than nesting similar combinations of Type and Size under the same outline box.

I noticed that when I hard code the following the script does what I want it to.

Platform(dt,

     If(Checkbox1 == 1,

          Control Chart(

               Sample Label( :Date ),

               Phase( :Machine ),

               KSigma( 3 ),

               Chart Col(:Variable1, Levey Jennings( Show Control Limits( 0 ))),

               Chart Col(:Variable2, Levey Jennings( Show Control Limits( 0 ))),

               By( :Size, :Type )

          )

     )

)

With this knowledge what I would like to do is create a variable for the Chart Col() lines. This variable will change depending on what check boxes are selected. The problem is I don't know what I need to assign to the variable and how I need to call it within the Control Chart command. I tried various combinations of expr, eval expr, and eval but none of that has worked.

Chart_Insert = Expr(Chart Col(:Variable2, Levey Jennings( Show Control Limits( 0 ))));


This seems to assign the expression to the variable correctly, but I couldn't figure out what combination of Eval Expr and Eval I needed in order to add it to the Control Chart command.

I apologize if this question is worded poorly. If any clarification is needed let me know. Also I don't know how to properly add code to a question so I'm sorry if the formatting gets messed up.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

You can build the chart command as a string and then execute it with eval(parse()). 

nw = new window("Get Variables", << modal(),

    variable_cb = checkbox({"Variable1", "Variable2", "Variable3", "Variable4", "Variable5"}),

    button box("OK", checked_list = variable_cb << get selected)

);

nc = nitems(checked_list);

chart_txt = "";

if (nc > 0,

    for (i = 1, i <= nc, i++,

        one_var = checked_list[i];

        chart_txt = chart_txt || evalinsert("Chart Col( :^one_var^, Levey Jennings( Show Control Limits( 0 ) ) ),");

    );

    cc_expr = evalinsert(

"\[nw = New Window( "Charts",

    Platform(

        dt,

        Control Chart(

            Sample Label( :Date ),

            Phase( :Machine ),

            KSigma( 3 ),

            ^chart_txt^

            By( :Size, :Type )

        )

    )

)]\");

    eval(parse(cc_expr));

);

2 REPLIES
Solution

You can build the chart command as a string and then execute it with eval(parse()). 

nw = new window("Get Variables", << modal(),

    variable_cb = checkbox({"Variable1", "Variable2", "Variable3", "Variable4", "Variable5"}),

    button box("OK", checked_list = variable_cb << get selected)

);

nc = nitems(checked_list);

chart_txt = "";

if (nc > 0,

    for (i = 1, i <= nc, i++,

        one_var = checked_list[i];

        chart_txt = chart_txt || evalinsert("Chart Col( :^one_var^, Levey Jennings( Show Control Limits( 0 ) ) ),");

    );

    cc_expr = evalinsert(

"\[nw = New Window( "Charts",

    Platform(

        dt,

        Control Chart(

            Sample Label( :Date ),

            Phase( :Machine ),

            KSigma( 3 ),

            ^chart_txt^

            By( :Size, :Type )

        )

    )

)]\");

    eval(parse(cc_expr));

);

jbakri21

Community Trekker

Joined:

Jul 8, 2016

Thank you so much for this response. This helped me solve the problem and

taught me three new things that will be immensely useful in the future.

parse, evalinsert, and "\[ text with "quotes" inside quotes]\"

You rock!!