Select / Case

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.

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.

Declaration

<AMSELECTCASE EXPRESSION="text">

<AMCASE CONSTANT="text">

</AMCASE>

</AMSELECTCASE>

Example

This example uses a Select/Case combination along with a Weekday() function to determine the day of the week.

<AMSELECTCASE EXPRESSION="%Weekday(Now())%">

<AMCASE CONSTANT="1">

<AMSHOWDIALOG>Today is Sunday.</AMSHOWDIALOG>

</AMCASE>

<AMCASE CONSTANT="2">

<AMSHOWDIALOG>Today is Monday.</AMSHOWDIALOG>

</AMCASE>

<AMCASE CONSTANT="3">

<AMSHOWDIALOG>Today is Tuesday.</AMSHOWDIALOG>

</AMCASE>

<AMCASE CONSTANT="4">

<AMSHOWDIALOG>Today is Wednesday.</AMSHOWDIALOG>

</AMCASE>

<AMCASE CONSTANT="5">

<AMSHOWDIALOG>Today is Thursday.</AMSHOWDIALOG>

</AMCASE>

<AMCASE CONSTANT="6">

<AMSHOWDIALOG>Today is Friday.</AMSHOWDIALOG>

</AMCASE>

<AMCASE CONSTANT="7">

<AMSHOWDIALOG>Today is Saturday.</AMSHOWDIALOG>

</AMCASE>

<AMCASE CONSTANT="8">

<AMSHOWDIALOG>Something went horribly wrong.</AMSHOWDIALOG>

</AMCASE>

</AMSELECTCASE>

</AMIF>

See Also: If, If Compare Files, If Folder Exists, If Last Step, If Pixel Exists, If Process Running, If Text Contains, If Windows Exists, End If, End Select/Case, Goto, Label

General Tab (Select)

Property

Type

Required

Default

Markup

Description

Goto case matching result of

Text

Yes

(Empty)

EXPRESSION="%Day()%"

Specifies a valid BASIC expression.

General Tab (Case)

Property

Type

Required

Default

Markup

Description

Case

Text

No

(Empty)

CONSTANT="text"

Used to separate the task steps to run for each Case that the Select expression could return. Otherwise, select Default Case, which defines a block of steps to execute if anything other than the defined cases are returned.