If

Declaration

<AMIF EXPRESSION="text">

See Also

Description

Begins a block of steps that are executed conditionally.  

Practical Usage

Very often when you create a task, you want it to perform different actions for different decisions. You can use conditional statements in your code to do this. The If action along with the Else action are conditional statements that can perform different actions during the course of a task depending on the result of an expression evaluation. If the result evaluates to TRUE, AutoMate will execute the block of steps immediately following the If action up until an End If step is encountered, otherwise the block will be skipped (or if an Else statement is encountered it will execute that block of steps).

NOTE: All If actions 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.

Parameters

General Tab

Property

Type

Required

Default

Markup

Description

Expression

Text

Yes

(Empty)

EXPRESSION="1 > 2"

Indicates a valid BASIC expression. The Simple method allows you to enter simple expressions. 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 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 allows you to 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 and Functions

All text fields allow the use of expressions such as variables, functions or AutoMate extended functions, which can be entered by surrounding the expression in percentage signs (example: %FileDateTime(myVar)% or %myVar%, %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on function

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.

 

Sample Task 1 - A simple task using If action - 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 Task 2 - This sample task demonstrates the following:

  1. Use of the Input Box 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

 

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

 

↑ Top of Page