Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted

Hello,

I have two groups of radio button groups, Group 1 and Group 2. Group 1 has two radio buttons, RB1 and RB2 while Group 2 has two radio buttons RB3 and RB4. When a user selects RB2, I want the script to select RB4 and run the jsl that is behind the selection of RB4. Currently, I can get the script to select RB4 but it does not also run the jsl behind RB4.

Any thoughts would be appreciated.

Thanks,

Martin

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Forgot that part:

rb4_expr = expr(

print("Running RB 4 Code");

);

nw = new window("Radio Button Demo",

hlistbox(

panelbox("Group 1",

rb1 = radio box({"RB 1", "RB 2"},

one_rb = rb1 << get selected;

if (one_rb == "RB 1",

// then

print("Running RB 1 Code");

,

// else

one_rb == "RB 2",

print("Running RB 2 Code");

rb4_expr;

rb2 << set (2);

);

),

),

panelbox("Group 1",

rb2 = radio box({"RB 3", "RB 4"},

one_rb = rb2 << get selected;

if (one_rb == "RB 3",

// then

print("Running RB 3 Code");

,

// else

one_rb == "RB 4",

rb4_expr;

);

)

)

)

);

6 REPLIES 6
Highlighted

rb4_expr = expr(

print("Running RB 4 Code");

);

nw = new window("Radio Button Demo",

hlistbox(

panelbox("Group 1",

rb1 = radio box({"RB 1", "RB 2"},

one_rb = rb1 << get selected;

if (one_rb == "RB 1",

// then

print("Running RB 1 Code");

,

// else

one_rb == "RB 2",

print("Running RB 2 Code");

rb4_expr;

);

),

),

panelbox("Group 1",

rb2 = radio box({"RB 3", "RB 4"},

one_rb = rb2 << get selected;

if (one_rb == "RB 3",

// then

print("Running RB 3 Code");

,

/ else

one_rb == "RB 4",

rb4_expr;

);

)

)

)

);

Highlighted

So this is close.  I was hoping that in the section of the code when RB 2 is selected - RB 4 would be selected automatically - causing the code of RB 4 to run.  Does this make sense?

Thanks

Highlighted

Forgot that part:

rb4_expr = expr(

print("Running RB 4 Code");

);

nw = new window("Radio Button Demo",

hlistbox(

panelbox("Group 1",

rb1 = radio box({"RB 1", "RB 2"},

one_rb = rb1 << get selected;

if (one_rb == "RB 1",

// then

print("Running RB 1 Code");

,

// else

one_rb == "RB 2",

print("Running RB 2 Code");

rb4_expr;

rb2 << set (2);

);

),

),

panelbox("Group 1",

rb2 = radio box({"RB 3", "RB 4"},

one_rb = rb2 << get selected;

if (one_rb == "RB 3",

// then

print("Running RB 3 Code");

,

// else

one_rb == "RB 4",

rb4_expr;

);

)

)

)

);

Highlighted

So if I understand this correctly, every time RB 2 is selected, "Running RP 2 Code" is printed, then "Running RP 4 Code" is printed via the Expr command (not sure why this can not be just added directly into the RB 2 code, without the Expr command), and then the RP 4 button is selected.  It is not by virture of the RP 4 button being selected that the "Running RP 4 Code" is printed when the RP 2 button is selected.  Correct?

Is the benefit of using the "rb4_expr" reusing the same code for two different parts of the program?

Thanks

Highlighted

So if I understand this correctly, every time RB 2 is selected, "Running RP 2 Code" is printed, then "Running RP 4 Code" is printed via the Expr command (not sure why this can not be just added directly into the RB 2 code, without the Expr command), and then the RP 4 button is selected.

Yes that's correct.

It is not by virtue of the RP 4 button being selected that the "Running RP 4 Code" is printed when the RP 2 button is selected.  Correct?

Yes.

Is the benefit of using the "rb4_expr" reusing the same code for two different parts of the program?

Yes.

This is straight "call-back" programming for a dialog box.  It's more work than straight linear programming; you have to do more housekeeping.

Highlighted

There is an optional argument for rb << set() to run the script besides selecting the button.

rb2 << set( 2, run script( 1 ) );

The script will only run if the button is not already selected, i.e. only the first time unless RB 4 is deselected. PMroz code forces the script to run every time RB 2 is selected/clicked. Compare his code with the below:

nw = New Window( "Radio Button Demo",

H List Box(

Panel Box( "Group 1",

{"RB 1", "RB 2"},

one_rb = rb1 << get selected;

If(

one_rb == "RB 1",

// then

Print( "Running RB 1 Code" ),

// else

one_rb == "RB 2",

Print( "Running RB 2 Code" );

rb2 << set( 2, run script( 1 ) );

))),

Panel Box( "Group 1",

{"RB 3", "RB 4"},

one_rb = rb2 << get selected;

If(

one_rb == "RB 3",

// then

Print( "Running RB 3 Code" ),

// else

one_rb == "RB 4", Print( "Running RB 4 Code" )

)))));

Article Labels

There are no labels assigned to this post.