IIf Function

与えられた表式を評価して得られる論理値に基づいて、2 つある選択肢の 1 つを結果として返します。

Syntax:


IIf (Expression, ExpressionTrue, ExpressionFalse)

Parameters:

Expression: 評価の対象とする表式。表式の評価結果が True となった場合は ExpressionTrue を返し、それ以外の場合は ExpressionFalse を返します。

ExpressionTrue, ExpressionFalse: 論理判定の結果として返す表式。2 つある表式の 1 つを、判定結果に応じて返します。

note

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 無効なプロシージャー呼び出しです

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

If or Select Case statements

Switch function

ご支援をお願いします!