Select - Begin Select

Declaration

<AMPROCESSES ACTIVITY="end" DOMAINNAME="text" REMOTEMACHINE="text" USERNAME="text" PASSWORD="text (encrypted)" PROCESSNAME="text" />

Description:

Executes the block of steps following the Begin case step matching the result of the specified expression.

Practical Usage

The Select/Case combination is a useful alternative to the If condition activity. Normally, If condition is used to evaluate an expression and return either TRUE or FALSE depending on the outcome. However, the Select/Case combination can be used to evaluate an expression which allows several outcomes to be reached. For example, for a simple expression such as 1=1 (true) or 1>2 (false), it would be best to use IF condition. 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 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 steps which segregate the activities to execute for each Case that matches the expression entered in the Begin select step. 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 in the sample task below.

All Begin select activities must be followed at some point with an End select step to mark the end of a block of Select/Case steps. Additionally, all Begin case activities must be followed at some point with an End case step to mark the end of a block of steps started by a preceding Begin case activity.

Parameters

General

Property

Type

Required

Default

Markup

Description

Goto case matching result of

Text

Yes

(Empty)

EXPRESSION="%Day()%"

Specifies a valid BASIC expression.

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.

Description: This example uses a Select/Case combination along with a Weekday() function to determine the current 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>