Subscribe Bookmark RSS Feed

Repopulating a List Box in JMP 8/9

I'm upgrading some scripts to make better use of JMP 9 capabilities at the moment, and have hit a difficulty which could be either trivial or rather complex - I don't know which.  In a nutshell, I need to be able to select a column of a data table from a list box and perform an action with it - no problem there - but I also need to allow for the possibility that the names of the data table from which I'm making the selection could be changed during the running of the script. The following is a considerably cut-down version of the part of the script which illustrates the problem:

clear log();

dt = new table("DT",

new column("AAA", numeric, values([1, 2, 3])),

new column("BBB", numeric, values([4, 5, 6])),

new column("CCC", numeric, values([7, 8, 9])),

);

Expr_Perform_Some_Action = expr(

// e.g. write the column name to the log;

selected_column = lb << get selected;

show(column(dt, selected_column) << get name)

);

lb_list = dt << get column names;

lb = listbox(lb_list, eval(Expr_Perform_Some_Action));

Expr_Reset_DT_to_ABC = expr(

column(dt, "DDD") << set name("AAA");

column(dt, "EEE") << set name("BBB");

column(dt, "FFF") << set name("CCC");

);

Expr_Reset_DT_to_DEF = expr(

column(dt, "AAA") << set name("DDD");

column(dt, "BBB") << set name("EEE");

column(dt, "CCC") << set name("FFF");

);

Expr_Repopulate_LB = expr(

// Get rid of all the old items in the list;

for(i=1, i<=nItems(lb_list), i++,

lb << set selected(i);

);

lb << remove selected;

// Replace them with the new ones;

lb_list = dt << get column names;

lb << append(lb_list);

);

nw = new window("My Window",

lb,

buttonbox("Reset Columns of DT to DEF", eval(Expr_Reset_DT_to_DEF); eval(Expr_Repopulate_LB)),

buttonbox("Reset Columns of DT to ABC", eval(Expr_Reset_DT_to_ABC); eval(Expr_Repopulate_LB))

);

nw << move window(600, 100); // Move it so we can see it;

The above runs as I want it to in JMP 8, but not in JMP 9 (or rather, it throws up as many errors as there are columns in the data table). I think I can see why it doesn't work: in JMP 9 my selecting an item in the list box (lb << set selected(i)) to remove it from the list is causing the action associated with making such a selection to be performed. The question is, how can I rescript it so that this doesn't happen?

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

JMP 9 has a new method which I use extensively for listboxes: remove all

This code works fine in JMP 9:

Clear Log();

dt = New Table( "DT",

    New Column( "AAA", numeric, values( [1, 2, 3] ) ),

    New Column( "BBB", numeric, values( [4, 5, 6] ) ),

    New Column( "CCC", numeric, values( [7, 8, 9] ) ),

);

Expr_Perform_Some_Action = Expr(

// e.g. write the column name to the log;

    selected_column = lb << get selected;

    Show( Column( dt, selected_column ) << get name )

    ;

);

lb_list = dt << get column names;

lb = List Box( lb_list, Eval( Expr_Perform_Some_Action ) );

Expr_Reset_DT_to_ABC = Expr(

    Column( dt, "DDD" ) << set name( "AAA" );

    Column( dt, "EEE" ) << set name( "BBB" );

    Column( dt, "FFF" ) << set name( "CCC" );

);

Expr_Reset_DT_to_DEF = Expr(

    Column( dt, "AAA" ) << set name( "DDD" );

    Column( dt, "BBB" ) << set name( "EEE" );

    Column( dt, "CCC" ) << set name( "FFF" );

);

Expr_Repopulate_LB = Expr(

// Get rid of all the old items in the list;

    lb << remove all;

   

// Replace them with the new ones;

    lb_list = dt << get column names;

    lb << append( lb_list );

);

nw = New Window( "My Window",

    lb,

    Button Box( "Reset Columns of DT to DEF",

        Eval( Expr_Reset_DT_to_DEF );

        Eval( Expr_Repopulate_LB );

    ),

    Button Box( "Reset Columns of DT to ABC",

        Eval( Expr_Reset_DT_to_ABC );

        Eval( Expr_Repopulate_LB );

    )

);

nw << move window( 600, 100 ); // Move it so we can see it;

3 REPLIES
ms

Super User

Joined:

Jun 23, 2011

One approach that seem to work, at least in the above example, is to replace rather than repopulate.

Starting from "Expr_Repopulate_LB...", try this code. Only essential change is the expression Expr_Repopulate_LB. I also made a lb_expr as the lb is drawn repeatedly.

lb_expr=expr(lb = listbox(lb_list, eval(Expr_Perform_Some_Action)));


Expr_Repopulate_LB = expr(

// Replace with updated listbox;

lb_list = dt << get column names;

lb<<delete;

lb = eval(lb_expr);

nw << prepend(lb);

);

nw = new window("My Window",

eval(lb_expr),

buttonbox("Reset Columns of DT to DEF", eval(Expr_Reset_DT_to_DEF);eval(Expr_Repopulate_LB)),

buttonbox("Reset Columns of DT to ABC", eval(Expr_Reset_DT_to_ABC); eval(Expr_Repopulate_LB))

);

Solution

JMP 9 has a new method which I use extensively for listboxes: remove all

This code works fine in JMP 9:

Clear Log();

dt = New Table( "DT",

    New Column( "AAA", numeric, values( [1, 2, 3] ) ),

    New Column( "BBB", numeric, values( [4, 5, 6] ) ),

    New Column( "CCC", numeric, values( [7, 8, 9] ) ),

);

Expr_Perform_Some_Action = Expr(

// e.g. write the column name to the log;

    selected_column = lb << get selected;

    Show( Column( dt, selected_column ) << get name )

    ;

);

lb_list = dt << get column names;

lb = List Box( lb_list, Eval( Expr_Perform_Some_Action ) );

Expr_Reset_DT_to_ABC = Expr(

    Column( dt, "DDD" ) << set name( "AAA" );

    Column( dt, "EEE" ) << set name( "BBB" );

    Column( dt, "FFF" ) << set name( "CCC" );

);

Expr_Reset_DT_to_DEF = Expr(

    Column( dt, "AAA" ) << set name( "DDD" );

    Column( dt, "BBB" ) << set name( "EEE" );

    Column( dt, "CCC" ) << set name( "FFF" );

);

Expr_Repopulate_LB = Expr(

// Get rid of all the old items in the list;

    lb << remove all;

   

// Replace them with the new ones;

    lb_list = dt << get column names;

    lb << append( lb_list );

);

nw = New Window( "My Window",

    lb,

    Button Box( "Reset Columns of DT to DEF",

        Eval( Expr_Reset_DT_to_DEF );

        Eval( Expr_Repopulate_LB );

    ),

    Button Box( "Reset Columns of DT to ABC",

        Eval( Expr_Reset_DT_to_ABC );

        Eval( Expr_Repopulate_LB );

    )

);

nw << move window( 600, 100 ); // Move it so we can see it;

Perfect - both methods solve the problem.

Many thanks guys,

David