Select - Begin case

Declaration

<AMCASE />

Related Topics   

Description

Executes the steps following this step if the case matches the expression result of an enclosing Begin select step.

Practical Usage

The Select/Case activity combination (also known as Select/Case statement) are conditional elements that can run one of several groups of statements, depending on the value of an expression. A single expression is initially evaluated. The value of the expression is then compared with the values for each Case in the structure. If there is a match, the block of steps associated with that Case is executed. Select/Case can be a useful alternative to If/Else in situations where evaluation of an expression may result to several outcomes. It is best to use If/Else to evaluate simple expressions that result to TRUE/FALSE such as 1=1 (TRUE) or 1>2 (FALSE). However, 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 comprehensible, and at runtime, the evaluation of the expression occurs only once rather than repeated execution of If/Else activities with individual comparison.

The Select/Case combination of steps works by first using a Begin select activity which contains the expression to evaluate, for example %Weekday(Now())% which returns 1 through 7 depending on the current day of the week (1=Sunday, 2=Moday, etc.). Immediately following the Begin select step are the individual Begin case/End case block of steps which segregate the activities to execute for each case that matches the expression entered in the Begin select step. The last block of 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 in the sample task below.

NOTE: All Begin select steps must be followed at some point with an End select step to mark the end of a block of cases. Additionally, all Begin case steps must be followed at some point with an End case step to mark the end of a block of steps to be performed by each case.

Parameters

General

Property Type Required Default Markup Description
Case Text/Number No (Empty) CONSTANT="1" If enabled, specifies the block of steps to run for each Case that the Select expression could return. If this parameter is enabled, the Default case parameter is disabled.
Default case --- --- --- --- If enabled, specifies a block of steps to execute if anything other than the defined cases are returned.  If this parameter is enabled, the Case parameter is disabled.
NOTE: This parameter does not contain markup and is only displayed in visual mode for task construction and configuration purposes.

Description

Error Causes

On Error

Example

NOTE:
  • The sample AML code below can be copied and pasted directly into the Steps Panel of the Task Builder.
  • Parameters containing user credentials, files, file paths, and/or other information specific to the task must be customized before the sample code can run successfully.

Description

This example uses a Select/Case combination along with a Weekday() function to determine the day of the week (1=Sunday, 2=Moday, etc.). A message box that corresponds to the matching case will display the correct answer.

Copy
<AMSELECTCASE EXPRESSION="%Weekday(Now)%" />
<AMCASE CONSTANT="1" />
<AMSHOWDIALOG MESSAGE="Today is Sunday" />
<AMCASE ACTIVITY="endcase" />
<AMCASE CONSTANT="2" />
<AMSHOWDIALOG MESSAGE="Today is Monday" />
<AMCASE ACTIVITY="endcase" />
<AMCASE CONSTANT="3" />
<AMSHOWDIALOG MESSAGE="Today is Tuesday" />
<AMCASE ACTIVITY="endcase" />
<AMCASE CONSTANT="4" />
<AMSHOWDIALOG MESSAGE="Today is Wednesday" />
<AMCASE ACTIVITY="endcase" />
<AMCASE CONSTANT="5" />
<AMSHOWDIALOG MESSAGE="Today is Thursday" />
<AMCASE ACTIVITY="endcase" />
<AMCASE CONSTANT="6" />
<AMSHOWDIALOG MESSAGE="Today is Friday" />
<AMCASE ACTIVITY="endcase" />
<AMCASE CONSTANT="7" />
<AMSHOWDIALOG MESSAGE="Today is Saturday" />
<AMCASE ACTIVITY="endcase" />
<AMCASE CONSTANT="8" />
<AMSHOWDIALOG MESSAGE="Something went horribly wrong" />
<AMCASE ACTIVITY="endcase" />
<AMSELECTCASE ACTIVITY="end" />