Compartir a través de


ICASE( ) Function

Evaluates the results from a list of conditions.

ICASE( lCondition1, eResult1 [, lCondition2, eResult2] ... 
   [, eOtherwiseResult])

Parameters

  • lCondition
    Specifies a condition as a logical expression to evaluate.

    If lCondition evaluates to False (.F.), ICASE( ) continues to evaluate the next condition and returns the corresponding eResult for that condition if it evaluates to True (.T.). If lCondition evaluates to null (.NULL.), Visual FoxPro treats lCondition as if it evaluated to False (.F.).

  • eResult
    Specifies a result to return if lCondition evaluates to True (.T.).
  • eOtherwiseResult
    Contains the result returned if all conditions evaluate to False (.F.).

Return Value

ICASE( ) returns the first eResult as soon as lCondition evaluates to True (.T.).

If all conditions evaluate to False (.F.), ICASE( ) returns eOtherwiseResult.

If eOtherwiseResult is omitted, and all conditions evaluate to False (.F.), ICASE( ) returns null (.NULL.).

Remarks

You must always pass a set of two parameters to ICASE( ). If you pass an odd number of parameters, the last parameter is treated as the return value for eOtherwiseResult.

You can pass up to 100 pairs of parameters for ICASE( ).

If you use a long ICASE( ) expression in a filter expression, such as in a FOR or WHERE clause, make sure that SYS(3055) is set to an appropriate complexity level to avoid generating an error. For more information, see SYS(3055) - FOR and WHERE Clause Complexity.

Example

The following example demonstrates different scenarios using ICASE( ) to evaluate expressions and returning certain values based on the results of those expressions.

The following line of code displays "First is true" because the first expression evaluates to True (.T.).

? ICASE(1+1=2,"First is true",1+1=3,"Second is false","None are true")

The following line of code displays "Second is true" because the first expression evaluates to False (.F.), but the second expression evaluates to True (.T.).

? ICASE(1+2=2,"First is false",1+2=3,"Second is true","None are true")

The following line of code displays "None are true", which is the last result specified, because the first and second expressions evaluate to False (.F.).

? ICASE(1+2=2,"First is false",1+1=3,"Second is false","None are true")

See Also

Reference

IIF( ) Function
EVALUATE( ) Function
EVL( ) Function

Other Resources

Functions