Column switcher & try functionHi,
Is it possible to use the try function in a column switcher script? I´m creating a script where I add a column switcher fore a few chosen columns to a graph which works fine. However, sometimes a column will be missing which will make the script stop. Therefore, I´m trying to use the try function for each of the relevant columns (as I don´t want all columns in the column switcher) but I can´t make it work.
dt << Column Switcher(
try((:RER), throw("RER does not exist")),
try((:VO2), throw("VO2 does not exist")),
try(:Name( "Drink-[ml]" ), throw("Drink-[ml] does not exist"))
);
Is it possible or is there a better way to do this?
Br Julie
Re: Column switcher & try functionHere is how I would do it
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
// set desired list of columns to be in column switcher
desiredColList = {"Height", "Weight", "Zippy"};
// remove from list, columns that are not available
For( i = N Items( desiredColList ), i >= 1, i--,
If( Try( Column( dt, desiredColList[i] ) << get name, "" ) == "",
Remove From( desiredColList, i, 1 )
)
);
// If columns are available, run the platform
If( N Items( desiredColList ) > 0,
ow = oneway( x( :age ), y( :height ) );
ow << Column Switcher( :height, desiredColList );
);Re: Column switcher & try functionI would use the Try() function outside of the message. Build the message conditionally. Like this:
Names Default to Here( 1 );
dt = Open( "$SAMPLE_DATA/Fitness.jmp" );
gb = dt << Graph Builder(
Size( 532, 456 ),
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables( X( :Age ), Y( :Oxy ) ),
Elements( Points( X, Y, Legend( 3 ) ) )
);
alt cols = List();
Try(
Insert Into( alt cols, Column( dt, "Age" ) )
);
Try(
Insert Into( alt cols, Column( dt, "Weight" ) )
);
Try(
Insert Into( alt cols, Column( dt, "Runtime" ) )
);
col switcher expr = Expr( Column Switcher( :age ) );
Insert Into( col switcher expr, alt cols );
Eval(
Insert(
Expr( Send( gb ) ),
Name Expr( col switcher expr )
)
);