Cond

(Engine-Level Function)

Description: Returns the result of one of two expressions depending upon the result of a conditional expression.
Returns: Varies
Usage: Script or steady state.
Function Groups: Logic Control
Related to: Case | IfElse | IfThen
Format: Cond(Condition, Value1, Value2)
Parameters:  
Condition
Required. Any numeric expression giving the conditional value to use for the test. If Condition is true (i.e. not equal to zero), the value of the Value1 parameter is returned.
If Condition is false (i.e. equal to zero), the value of the Value2 parameter is returned.
If Condition is invalid, the return value is invalid.
Value1
Required. Any expression whose value is returned if the Condition parameter is true.
Value2
Required. Any expression whose value is returned if the Condition parameter is false.
Comments:

This function will return either Value1 or Value2 based on the truth of Condition. This means that the function may return a valid result even if one of the Value parameters is invalid (i.e. the one not selected).

  • If Cond is executed in a script, and the Condition parameter selects one of the parameters, the other is not evaluated (unless Condition is invalid, and then neither parameter is evaluated).
  • If Cond is executed in steady state, both Value1 and Value2 are evaluated, but only one result is returned.

Cond may be used on the left side of an assignment, in which case Value1 and Value2 may be variables, and one of Value1 and Value2 will receive the assignment (depending on the Condition parameter).

This function is used extensively to change screen images based upon variable values. For example, it can be used to change a color of a bar if it is used within the Bar statement in the Foreground color parameter.
The return value is optional.

Example:

  Y = Cond(X == 3, 4, 5);

Y will be set invalid if x is invalid. If x is 3, y will be 4. Otherwise Y will be 5.

  Cond(X == 3, A, B) = 6;

If X is invalid, nothing happens. If X is 3, A will be set to 6, otherwise B will be set to 6.