Select/Case Action Icon

Select / Case

Declaration

<AMSELECTCASE EXPRESSION="text">

<AMCASE CONSTANT="text">

</AMCASE>

</AMSELECTCASE>

See Also

Else | End If | End Select/Case | Goto | If | If Compare Files | If File Exists | If Folder Exists | If Last Step | If Pixel Exists | If Process Running | If Text Contains | If Windows Exists | Label | Select/Case

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 Properties (Select)

Property

Type

Required

Default

Markup

Description

Goto case matching result of

Text

Yes

(Empty)

EXPRESSION="%Day()%"

Specifies a valid BASIC expression.

 

General Properties (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.

 

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

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

 

Description: 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>

 

↑ [Top of Page]