Text Documents (Writer)
HTML Documents (Writer Web)
Spreadsheets (Calc)
Presentations (Impress)
Drawings (Draw)
Database Functionality (Base)
Formulae (Math)
Charts and Diagrams
Macros and Scripting
Office Installation
Common Help Topics
OneOffice Logo

IIf Function

Returns one of two possible function results, depending on the logical value of the evaluated expression.

Syntax:


IIf (Expression, ExpressionTrue, ExpressionFalse)

Parameters:

Expression: An expression that you want to evaluate. If the expression evaluates to True, the function returns the result of ExpressionTrue, otherwise it returns the result of ExpressionFalse.

ExpressionTrue, ExpressionFalse: Any expressions, one of which will be returned as the function result, depending on the logical evaluation.

IIf evaluates both ExpressionTrue and ExpressionFalse even if it returns only one of them. If one of the expressions results in error, the function returns the error. For example, do not use IIF to bypass a possible division by zero result.

Error codes:

5 Invalid procedure call

Example:


REM Returns the maximum of 3 values
Function Max (A As Double, B As Double, C, As Double) As Double
    Max = IIf( A >= B, A, B)
    Max = IIf( C >= Max, C, Max)
End Function
REM Bad usage of function IIf
Function Inverse(A As Double) As Double
    Inverse = IIf( A = 0, 0, 1/A )
End Function