The IIF operator returns one of two values, depending on an expression that returns a value of type LOGIC. The IIF operator is of the form:
IIF( conditionExpression, trueExpression, falseExpression ) |
conditionExpression may be any expression that returns a value of type LOGIC, or a type that can be implicitly converted to LOGIC.
If conditionExpression evaluates to TRUE, trueExpression is evaluated and is the result. If conditionExpression evaluates to FALSE, falseExpression is evaluated and is the result.
Only one of the two expressions is ever evaluated.
The return type of the IIF operator is determined by the following rules:
Given:
•tT is the type of trueExpression
•tF is the type of falseExpression
•tR is the return type of the IIF expression
1.If tT and tF are the same type, tR is that type.
2.If tT and/or tF is USUAL, then tT or tF is converted to USUAL if necessary, and tR is USUAL.
3.If tT can be implicitly converted to tF, tR is tF.
4.If tF can be implicitly converted to tT, tR is tT.
5.If tT can be implicitly converted to tF and tF can be implicitly converted to tT, then tR is ambiguous and a compiler error is raised.
6.If tT cannot be implicitly converted to tF and tF cannot be implicitly converted to tT, then tR is indeterminate and a compiler error s raised.
Note that if tT and tF are VOID, tR is VOID and the IIF operator cannot be used as an operand in another expression, or as a function or method parameter.
In this case, the IIF operator is essentially the same as an IF...ELSE...ENDIF construct and can only be used in stand-alone expression statements.
In cases 5 and 6, it may be possible to resolve the error by specifying an explicit cast on trueExpression or falseExpression.
This behavior is different than in some other XBase dialects In these dialects the return is usually determined by the following rules
1.If tT and tF are the same type, tR is that type.
2.Otherwise tT and tR are implicitly converted to USUAL and tR is USUAL.
You can use the /vo10 compiler option to enable this behavior in X#, but this is only recommended for code originally written in other environments, such as Visual Objects.
For compatibility with Visual Objects and several other dialects the IF() operator is also supported