If - Condition

Declaration

<AMIF EXPRESSION="text" USECOMPLEXUI="YES">

Related Topics   

Description

Begins a block of steps that are executed conditionally. The If condition along with an Else step are conditional statements that can perform different operations during the course of a task depending on the result of an expression evaluation. If the result evaluates to TRUE, the task will execute the block of steps immediately following this step up until an End if step is encountered. If the result evaluates to FALSE, the block will be skipped and execution will proceed directly after the End if step (or if an Else step is encountered, the task will execute that block of steps instead, up until an End if step is encountered).

NOTE: All IF activities must be followed at some point with an END IF step to mark the end of the code block that is to be executed if the expression is TRUE. For ease of use, by default, any IF activity added to the Task Builder's Steps panel is always followed by an END IF activity.

Practical Usage

Used to perform different activities for different decisions.

Parameters

General

Property

Type

Required

Default

Markup

Description

Expression

Text

Yes

(Empty)

  1. EXPRESSION="1 > 2"

  2. EXPRESSION="1 < 2"

Indicates a valid BASIC expression. The Simple method allows you to enter a simple expression by entering two values and selecting from the drop-down list of equality operators to be used to compare those values. The Complex method allows entry of more elaborate expressions.

NOTE: All literal strings (strings to be taken as themselves) must be enclosed in double quotes (Example: "string literal").

 

Description

Error Causes

On Error

examples

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

Sample 1:

This is a simple task using If condition activity - should result to TRUE.

 

<AMIF EXPRESSION="1 = 1">

     <AMMESSAGEBOX>The result of the expression is TRUE.</AMMESSAGEBOX>

<AMELSE />

     <AMMESSAGEBOX>The result of the expression is FALSE.</AMMESSAGEBOX>

</AMIF>

 

Sample 2:

This is a more complex task that demonstrates the following:

  1. Use of the Input Box activity to ask the user a question and retrieve the answer

  2. Use of custom BASIC functions

  3. Use of the IF activity

  4. Use of Expressions

 

<AMMESSAGEBOX WINDOWTITLE="Sample Task" BUTTONS="ok_cancel" ICON="information" ONSECONDBUTTONCLICK="stop">This sample task demonstrates the following:

1) Use of the Input Action to ask the user a question and retrieve the answer

2) Use of Custom BASIC Functions

3) Use of the IF action

4) Use of Expressions

Remember you can always stop a task in progress by pressing CTRL-ALT-END. Press okay to continue running the task or Cancel to stop now.</AMMESSAGEBOX>

<AMVARIABLE NAME="theanswer" DESCRIPTION=""></AMVARIABLE>

<AMSCRIPT>Function SquareNumber(thenum)

SquareNumber = thenum * thenum

End Function</AMSCRIPT>

<AMINPUTBOX RESULTVARIABLE="theanswer">What number would you like to square?</AMINPUTBOX>

<AMIF EXPRESSION="IsNumeric(theanswer) = true">

     <AMMESSAGEBOX>The number %theanswer% squared  is:

%SquareNumber(theanswer)%</AMMESSAGEBOX>

<AMELSE />

     <AMMESSAGEBOX>The text "%theanswer%" is not a valid number.  Please re-run and enter a valid number.</AMMESSAGEBOX>

</AMIF>