The Choose() function shortens scripts even more than Match(), provided the arguments are tested against integers. The syntax is:
Choose( expr, result1, result2, result3, ..., resultElse );
Suppose you have a data table with a group column of numeric values from 1 through 7. If the first cell contains the number 1, the following script returns x = "Low".
x = ( Choose( group, "Low", "Medium", "High", "Unknown" ); );
Show( x );
x = |
Creates the x variable.
|
Choose( |
Begins the Choose() loop.
|
group, |
Evaluates the value of group.
|
"Low", |
If the value of group is 1, return "Low".
|
"Medium", |
If the value of group is 2, return "Medium".
|
"High", |
If the value of group is 3, return "High".
|
"Unknown" |
|
) |
|
); |
Closes the x variable.
|
Show( x ); |
If(
group == 1, "Low",
group == 2, "Medium",
group == 3, "High",
"Unknown"
);
Match( group, 1, "Low", 2, "Medium", 3, "High", "Unknown" );