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 theIfcommand 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 keywordsIF,THEN,ELSE, andENDIFare not case sensitive.
- You cannot use theIF,THEN,ELSE, orENDIFoperators in an expression for anIfcommand.
- TheIfcommand will be run locally on the HMI Server,FactoryTalk View SEclient, orFactoryTalk View Studiothat issued the command.
- The commands specified as theTHENorELSEactions will be run where they would normally be run when issued from outside anIfcommand.
- TheIfcommand is processed synchronously. This means that when other commands are to be issued after theIfcommand, for example in a macro, the next command will not be issued until anyTHENorELSEcommands in theIfcommand string have been issued, or until an error is encountered in theIfcommand.
- If you place an ampersand (&) in front of the conditionalIfcommand, the system will not wait forTHENorELSEcommands to be run before processing subsequent commands.
- Do not confuse theIfcommand with a conditional expression such as you might you create in theExpressioneditor. Although both use conditional operators in their structure, you cannot usecommands as the action for a conditional expression that usesFactoryTalk View SEIF,THEN,ELSE, orENDIFoperators.
- Do not use the alarm functions in theExpressionseditor with theIfcommand because it will always return a 0 (zero). However, the alarm functions work correctly when used in theIf-Then_Elselogic in an expression.
Provide Feedback