Dynamic display box based on combo box selectionLooking for some help here, I can't get the display box to work correctly as it kept changing back to a blank window when "Option 1" is re-selected (some photos for reference).
Really appreciate the help!
names default to here(1);
Buttons = {"Button 1", "Button 2", "Button3"};
Boxes = {"Box 1", "Box 2", "Box 3"};
LB_Input_1 = lineupbox(ncol(2),spacing(5));
for(i=1,i<=nitems(Buttons),i++,
label1 = char(Buttons[i]);
bblabel1 = "clb_" || char(i);
eval(parse(evalinsert("\[LB_Input_1 << append(buttonbox("^label1^", ^bblabel1^ << append(clb2 << get selected)))]\")));
eval(parse(evalinsert("\[LB_Input_1 << append(^bblabel1^ = col list box("Numeric",minitems(1),maxitems(1),nlines(1)))]\")));
);
for(i=1,i<=nitems(Boxes),i++,
label1 = char(Boxes[i]);
neblabel1 = "neb_"||char(i);
eval(parse(evalinsert("\[LB_input_1 << append(Text box("^label1^"))]\")));
eval(parse(evalinsert("\[LB_input_1 << append(^neblabel1^ = Number edit box())]\")));
);
HB1 = hlistbox(
clb2 = filter col selector(dt1,all),
LB_input_1
);
LB_Input_2 = lineupbox(ncol(2),spacing(5));
for(i=1,i<=nitems(Buttons)-1,i++,
label1 = char(Buttons[i]);
bblabel1 = "clb_" || char(i);
eval(parse(evalinsert("\[LB_Input_2 << append(buttonbox("^label1^", ^bblabel1^ << append(clb2 << get selected)))]\")));
eval(parse(evalinsert("\[LB_Input_2 << append(^bblabel1^ = col list box("Numeric",minitems(1),maxitems(1),nlines(1)))]\")));
);
for(i=1,i<=nitems(Boxes)-1,i++,
label1 = char(Boxes[i]);
neblabel1 = "neb_"||char(i);
eval(parse(evalinsert("\[LB_input_2 << append(Text box("^label1^"))]\")));
eval(parse(evalinsert("\[LB_input_2 << append(^neblabel1^ = Number edit box())]\")));
);
HB2 = hlistbox(
clb2 = filter col selector(dt1,all),
LB_input_2
);
dt1 = current data table();
new window("Test",
vb1 = vlistbox(Text box(""),
Panel Box("Selection Option",H list box(text box("Select: "),
combo1 = combobox({"Option 1","Option 2"},
<< set function(function({this,index},
match(index,
1,
vb1 << append (try(view << delete);
view = HB1;
),
2,
vb1 << append (try(view << delete);
view = HB2;
)
)
))
)
)
),
text box (""),
view = HB1;
)
);



Consumer and Market ResearchRe: Dynamic display box based on combo box selection@jthi Thanks for explaining your debugging approach!
I do see the "Displaybox[]" quite often in the log but I guess I didn't really get what the log means. Thanks for the pointers!
Re: Dynamic display box based on combo box selectionSure. Hopefully this helps:
1. Open log window
2. Run the script -> Runs fine
3. Change option from Option 1 to Option 2 -> Works fine
4. Change option from Option 2 to Option 1 -> Display Box disappears
5. Change option from Option 1 back to Option 2 -> Display Box still missing
At this point I started wondering if something is wrong with HB1 and HB2, and if they get deleted when you change options.
6. Run script again. Highlight HB1 from the Script Window and run the script to get info on variable to Log Window (DisplayBox[ListBox])
7. Change option from Option 1 to Option 2. Highlight HB1 from the Script Window and run the script to get info on variable to Log Window (DisplayBox[])
8. Notice that ListBox has disappeared

9. Start figuring out what goes wrong and how to fix it
This might help you figure out what is going on: at some point HB1 and HB2 H List Boxes get deleted.
Re: Dynamic display box based on combo box selectionThanks @jthi
The solution works!
As a follow up though, could you clarify the 3-debugging-steps you mentioned ? I don't quite get that comment.
Issue and how to debug:
1. Run the script
2. Check the content of HB1 and HB2 (DisplayBox[ListBox])
3. Change to Option 2 and check content of HB1 (DisplayBox[])
Re: Dynamic display box based on combo box selectionIssue and how to debug:
1. Run the script
2. Check the content of HB1 and HB2 (DisplayBox[ListBox])
3. Change to Option 2 and check content of HB1 (DisplayBox[])
Quick (and dirty fix?) that could possibly help. See how I changed HB1 and HB2 reference locations and made them Expressions:
names default to here(1);
Buttons = {"Button 1", "Button 2", "Button3"};
Boxes = {"Box 1", "Box 2", "Box 3"};
HB1 = Expr(
LB_Input_1 = lineupbox(ncol(2),spacing(5));
for(i=1,i<=nitems(Buttons),i++,
label1 = char(Buttons[i]);
bblabel1 = "clb_" || char(i);
eval(parse(evalinsert("\[LB_Input_1 << append(buttonbox("^label1^", ^bblabel1^ << append(clb2 << get selected)))]\")));
eval(parse(evalinsert("\[LB_Input_1 << append(^bblabel1^ = col list box("Numeric",minitems(1),maxitems(1),nlines(1)))]\")));
);
for(i=1,i<=nitems(Boxes),i++,
label1 = char(Boxes[i]);
neblabel1 = "neb_"||char(i);
eval(parse(evalinsert("\[LB_input_1 << append(Text box("^label1^"))]\")));
eval(parse(evalinsert("\[LB_input_1 << append(^neblabel1^ = Number edit box())]\")));
);
hlistbox(
clb2 = filter col selector(dt1,all),
LB_input_1
);
);
HB2 = Expr(
LB_Input_2 = lineupbox(ncol(2),spacing(5));
for(i=1,i<=nitems(Buttons)-1,i++,
label1 = char(Buttons[i]);
bblabel1 = "clb_" || char(i);
eval(parse(evalinsert("\[LB_Input_2 << append(buttonbox("^label1^", ^bblabel1^ << append(clb2 << get selected)))]\")));
eval(parse(evalinsert("\[LB_Input_2 << append(^bblabel1^ = col list box("Numeric",minitems(1),maxitems(1),nlines(1)))]\")));
);
for(i=1,i<=nitems(Boxes)-1,i++,
label1 = char(Boxes[i]);
neblabel1 = "neb_"||char(i);
eval(parse(evalinsert("\[LB_input_2 << append(Text box("^label1^"))]\")));
eval(parse(evalinsert("\[LB_input_2 << append(^neblabel1^ = Number edit box())]\")));
);
hlistbox(
clb2 = filter col selector(dt1,all),
LB_input_2
);
);
dt1 = current data table();
new window("Test",
vb1 = vlistbox(Text box(""),
Panel Box("Selection Option",H list box(text box("Select: "),
combo1 = combobox({"Option 1","Option 2"},
<< set function(function({this,index},
try(view << delete);
match(index,
1,
vb1 << append (
view = HB1;
),
2,
vb1 << append (
view = HB2;
)
)
))
)
)
),
text box (""),
view = HB1;
)
);