Select/Case Action

Declaration

<AMSELECTCASE EXPRESSION="text">

<AMCASE CONSTANT="text">

</AMCASE>

</AMSELECTCASE>

See Also

    Select Action-Setting Properties, Else Action, The BASIC Language All Groups

Description

The "Select" action executes the block of steps following the case step matching the result of the specified expression.

The "Case" action executes the steps following this step if the Case matches the expression result of an enclosing Select step.

Practical Usage

The "Select/Case" action combination is a very useful alternative to using IF. Like the If Action, Select/Case allows decisions to be made during the execution of the task depending on the result of an expression evaluation, the difference is the speed and readability of the resulting task when one of several decisions can be reached. For example, for a simple expression such as 1=1 (true) or 1>2 (false), it would be best to use the IF action. For more complex decisions where there are several possible answers such as favoritecolor=red, blue, green or yellow, Select/Case would be a better choice. This is because Select/Case presents the task steps in a manner that is more readable, and at runtime, the evaluation of the expression occurs only once rather than needing repeated If Actions with individual comparison.

Select/Case works by first using a Select step with the expression to evaluate, for example %Day()% which returns 1 through 7 depending on the current day. Immediately following the Select step are the individual Case steps which segregate the task steps to run for each Case that the Select expression could return. The last Case block can optionally be what is called a "default case" which defines a block of steps to execute if anything other than the defined cases are returned. An example of this is shown below under Examples.

All Select actions must be followed at some point with an End Select action to mark the end of a block of Select/Case steps. Additionally, all Case actions must use an End Case action to end a block of steps started by a preceding Case action.

Parameters

General Tab (Select)

Goto case matching result of:

Text, Optional
MARKUP: EXPRESSION="%Day()%"

 

Specifies a valid BASIC expression.

General Tab (Case)

Case

Text, Optional
MARKUP: CONSTANT="text"

 

Used to separate the task steps to run for each Case that the Select expression could return.

Default Case

Defines a block of steps to execute if anything other than the defined cases are returned.

Notes

Custom Description

This action includes the Description tab for entering a custom step description.

More on setting custom step description

Standard Error Handling Options

This action also includes the standard Error Causes and On Error failure handling options/tabs.

More on Error Handling Options

Variables and Expressions

All text fields allow the use of expressions, which can be entered by surrounding the expression in percentage signs (example: %MYVARIABLE%, %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by pressing F2.

More on variables
More on expressions

More on the expression builder

Examples

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 <AMSELECTCASE EXPRESSION="%Weekday(Now())%">
<AMCASE CONSTANT="1">
  <AMMESSAGEBOX>Sunday</AMMESSAGEBOX>
</AMCASE>
<AMCASE CONSTANT="2">
  <AMMESSAGEBOX>Monday</AMMESSAGEBOX>
</AMCASE>
<AMCASE CONSTANT="3">
  <AMMESSAGEBOX>Tuesday</AMMESSAGEBOX>
</AMCASE>
<AMCASE CONSTANT="4">
  <AMMESSAGEBOX>Wednesday</AMMESSAGEBOX>
</AMCASE>
<AMCASE CONSTANT="5">
  <AMMESSAGEBOX>Thursday</AMMESSAGEBOX>
</AMCASE>
<AMCASE CONSTANT="6">
  <AMMESSAGEBOX>Friday</AMMESSAGEBOX>
</AMCASE>
<AMCASE CONSTANT="7">
  <AMMESSAGEBOX>Saturday</AMMESSAGEBOX>
</AMCASE>
<AMCASE>
  <AMMESSAGEBOX>Something went horribly wrong</AMMESSAGEBOX>
</AMCASE>
</AMSELECTCASE>