Home Search

DriveWorks Pro 21
If

Send Feedback

If

Evaluates a given argument and returns one value when the argument is true and another when the argument is false.

Syntax

If( [Condition], [ValueIfConditionIsTrue], [ValueIfConditionIsFalse] )

Condition is any rule which, when calculated, returns either TRUE or FALSE.

ValueIfConditionIsTrue is a rule or value which is returned if the condition, when calculated, returns TRUE.

ValueIfConditionIsFalse is a rule or value which is returned if the condition, when calculated, returns FALSE.

Examples

Rule

Meaning
If(FormSpinButtonReturn<=5, "Can be shipped in one container","Will be shipped in several packages.") Checks the return value from a spin button called FormSpinButton, and if the result is less than or equal to five, returns "Can be shipped in one container".

Comparing Values

Operator

Meaning
<Checks to see if the value on the left hand side of the operator is less than the value on the right hand side, and if so, returns TRUE, otherwise returns FALSE.
<=Checks to see if the value on the left hand side of the operator is less than, or equal to, the value on the right hand side, and if so, returns TRUE, otherwise returns FALSE.
>Checks to see if the value on the left hand side of the operator is greater than the value on the right hand side, and if so, returns TRUE, otherwise returns FALSE.
>=Checks to see if the value on the left hand side of the operator is greater than, or equal to, the value on the right hand side, and if so, returns TRUE, otherwise returns FALSE.
<>Checks to see if the value on the left hand side of the operator is not equal to the value on the right hand side, and if so, returns TRUE, otherwise returns FALSE.
=Checks to see if the value on the left hand side of the operator is the same as the value on the right hand side, and if so, returns TRUE, otherwise returns FALSE.

Nesting If

Multiple If statements can be nested so many conditions can be evaluated. In these cases the syntax of the single If statement is substituted for one of the conditions, as below:

If( [ ConditionA], [ ValueIfConditionAIsTrue], If( [ ConditionB], [ ValueIfConditionBIsTrue], [ ValueIfConditionBIsFalse] ) )

If statements are always evaluated from left to right. So in the example above

  • ConditionA is evaluated first
  • When ConditionA is TRUE the ValueIfConditionAIsTrue will be the result of the If statement. The remainder of the nested If will be ignored.
  • When ConditionA is FALSE the value in the second condition would usually be the result. But the example above initiates the evaluation of ConditionB
  • When ConditionB is TRUE the ValueIfConditionBIsTrue will be the result of the If statement. The remainder of the nested If will be ignored.
  • When ConditionB is FALSE the ValueIfConditionBIsFalse will be the result
DriveWorks Projects have no limits on the amount of If functions that can be nested as ValueIfTrue and ValueIfFalse arguments. Alternatively, to test many conditions, consider using tables and the functions DWVLookup and VLookup. Another alternative to nesting If statements is the ChooseFrom function.

If And/If Or

The And and Or functions can be nested in place of the Condition argument. In these cases the syntax of the And/Or function replaces the Condition portion of the If statement. For example:

If( And ( [ LogicalExpression1], [ LogicalExpression2] ) , [ ValueIfConditionIsTrue], [ ValueIfConditionIsFalse] )

When using And

  • When all LogicalExpressions within the And function are TRUE the ValueIfConditionIsTrue will be the result
  • When any of the LogicalExpressions within the And function are FALSE the ValueIfConditionIsFalse will be the result

If( Or ( [LogicalExpression1], [ LogicalExpression2] ) , [ ValueIfConditionIsTrue], [ ValueIfConditionIsFalse] )

When Or

  • When any of the LogicalExpressions within the Or function are TRUE the ValueIfConditionIsTrue will be the result
  • When all of the LogicalExpressions within the Or function are FALSE the ValueIfConditionIsFalse will be the result