If

The conditional
If
command provides a way to run a command, or commands, conditionally. The conditional
If
command can be used wherever other commands can be issued, except that conditional commands cannot be nested. This means that you cannot use an
If
command as the
THEN
or
ELSE
action for another
If
command.
Syntax
If <
expression
> THEN <
command
>; <
command
>;... [ELSE<
command
>; <
command
>;... ] ENDIF
where
<expression>
is a comparison (for example, Tag1 = Tag2 or Tag1 = Tag2+Tag3) or any expression that evaluates to a numeric value. An expression that evaluates to any non-zero number will be considered to be True. An expression that evaluates to zero will be considered to be False.
<command>
is any
FactoryTalk View SE
command or user-defined macro. Single or multiple commands or macros, separated by semi-colons, can be specified for the THEN or the ELSE action.
Remarks
If the expression evaluates to True, the THEN action is performed. If it evaluates to False and an ELSE action is specified, it will be performed. If the expression evaluates to False and no ELSE action has been specified, no action will be taken.
When using the
If
command, note that:
  • All parts of the
    If
    command statement must be on a single line.
  • The maximum command length is 5000 characters. The command will be truncated if substituted tag values cause the command to exceed this length.
  • The keywords
    IF
    ,
    THEN
    ,
    ELSE
    , and
    ENDIF
    are not case sensitive.
  • You cannot use the
    IF
    ,
    THEN
    ,
    ELSE
    , or
    ENDIF
    operators in an expression for an
    If
    command.
  • The
    If
    command will be run locally on the HMI Server,
    FactoryTalk View SE
    client, or
    FactoryTalk View Studio
    that issued the command.
  • The commands specified as the
    THEN
    or
    ELSE
    actions will be run where they would normally be run when issued from outside an
    If
    command.
  • The
    If
    command is processed synchronously. This means that when other commands are to be issued after the
    If
    command, for example in a macro, the next command will not be issued until any
    THEN
    or
    ELSE
    commands in the
    If
    command string have been issued, or until an error is encountered in the
    If
    command.
  • If you place an ampersand (
    &
    ) in front of the conditional
    If
    command, the system will not wait for
    THEN
    or
    ELSE
    commands to be run before processing subsequent commands.
  • Do not confuse the
    If
    command with a conditional expression such as you might you create in the
    Expression
    editor. Although both use conditional operators in their structure, you cannot use
    FactoryTalk View SE
    commands as the action for a conditional expression that uses
    IF
    ,
    THEN
    ,
    ELSE
    , or
    ENDIF
    operators.
  • Do not use the alarm functions in the
    Expressions
    editor with the
    If
    command because it will always return a 0 (zero). However, the alarm functions work correctly when used in the
    If-Then_Else
    logic in an expression.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal