<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Hello JMPsters,
I'm having a problem with the code below. I have a list of topics in a listbox, and I want to change what's shown in the tabs depending on what the user selects from the listbox. Try running the code and you'll see how it works.
The graph tab gets updated nicely, no matter which topic you click on.
The problem is with the first tab, which contains a tablebox. The first time you click on a topic the tablebox appears.

However if you click on the next topic and then back on the original topic you get a blank tab.

Thanks in advance if someone can figure it out.
topic_dt = New Table( "Example Topics", Add Rows( 5 ),
New Column( "Period", Numeric, Continuous, Format( "Best", 12 ),
Set Values( [1, 2, 3, 4, 5] ) ),
New Column( "AAAAA", Numeric, Continuous, Format( "Best", 12 ),
Set Values( [1, 2, 3, 4, 5] ) ),
New Column( "BBBBB", Numeric, Continuous, Format( "Best", 12 ),
Set Values( [5, 4, 3, 2, 1] ) ),
New Column( "CCCCC", Numeric, Continuous, Format( "Best", 12 ),
Set Values( [2, 3, 2, 3, 2] ) ),
New Column( "DDDDD", Numeric, Continuous, Format( "Best", 12 ),
Set Values( [3, 4, 2, 1, 5] ) )
);
topic_list = {"AAAAA", "BBBBB", "CCCCC", "DDDDD"};
tbl_expr = {};
graph_expr = {};
for (i = 1, i <= nitems(topic_list), i++,
one_topic = topic_list[i];
plist = topic_dt:Period << get values;
tlist = column(topic_dt, one_topic) << get values;
tbl_expr[i] =
vlistbox(
textbox("Table for topic " || one_topic),
tablebox(
number col box("Period", plist),
number col box(one_topic, tlist),
),
);
gb_expr = evalinsert(
"\[graph_expr[^i^] = expr(hlistbox(
gb = Graph Builder(
Show Control Panel( 0 ),
Variables( X( :Period ), Y( :Name("^one_topic^") ) ),
Elements(
Points( X, Y, Legend( 1 ), Jitter( 1 ) ),
Smoother( X, Y, Legend( 2 ) )
)
)
))]\");
eval(parse(gb_expr));
); // end loop
topic_list_expr = expr(
topic_mtx = topic_lb << get selected indices;
itopic = topic_mtx[1];
trend_tab << replace(1, "Tabulation",
vlistbox(
tbl_expr[itopic],
)
);
trend_tab << replace(2, "Graph",
eval(graph_expr[itopic]),
);
);
pvtrend_win = new window("Example",
hlistbox(
panel box("Topics",
topic_lb = listbox(topic_list, width(250), nlines(5), max selected(1),
topic_list_expr),
),
trend_tab = tab box(
"Tabulation",
vlistbox(
tbl_expr[1],
),
"Graph",
eval(graph_expr[1]),
),
)
);
topic_lb << set selected(1);
The problem seems to be with the display boxes in tbl_expr not being fully evaluated. I think this code works as intended:
topic_dt = NewTable( "Example Topics",
Add Rows( 5 ),
NewColumn( "Period", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1, 2, 3, 4, 5] ) ),
NewColumn( "AAAAA", Numeric, Continuous, Format( "Best", 12 ), Set Values( [1, 2, 3, 4, 5] ) ),
NewColumn( "BBBBB", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 4, 3, 2, 1] ) ),
NewColumn( "CCCCC", Numeric, Continuous, Format( "Best", 12 ), Set Values( [2, 3, 2, 3, 2] ) ),
NewColumn( "DDDDD", Numeric, Continuous, Format( "Best", 12 ), Set Values( [3, 4, 2, 1, 5] ) )
);
topic_list = {"AAAAA", "BBBBB", "CCCCC", "DDDDD"};
tbl_expr = {};
graph_expr = {};
For( i = 1, i <= NItems( topic_list ), i++,
one_topic = topic_list[i];
plist = topic_dt:Period << get values;
tlist = Column( topic_dt, one_topic ) << get values;
tbl_expr[i] = EvalExpr(
VListBox(
TextBox( "Table for topic " || Expr( one_topic ) ),
TableBox(
NumberColBox( "Period", Expr( plist ) ),
NumberColBox( Expr( one_topic ), Expr( tlist ) ),
)
)
);
graph_expr[i] = EvalExpr(
HListBox(
gb = Graph Builder(
Show Control Panel( 0 ),
Variables( X( :Period ), Y( AsColumn( Expr( one_topic ) ) ) ),
Elements( Points( X, Y, Legend( 1 ), Jitter( 1 ) ), Smoother( X, Y, Legend( 2 ) ) )
)
)
);
); // end loop
topic_list_expr = Expr(
topic_mtx = topic_lb << get selected indices;
itopic = topic_mtx[1];
trend_tab << replace( 1, "Tabulation", Eval(tbl_expr[itopic]) );
trend_tab << replace( 2, "Graph", Eval( graph_expr[itopic] ) );
);
pvtrend_win = NewWindow( "Example",
HListBox(
PanelBox( "Topics",
topic_lb = ListBox(
topic_list,
width( 250 ),
nlines( 5 ),
max selected( 1 ),
Eval( topic_list_expr )
),
),
trend_tab = TabBox( "Tabulation", VListBox( tbl_expr[1], ), "Graph", Eval( graph_expr[1] ) ),
)
);
topic_lb << set selected( 1 );