IIf Function

āĻŽā§‚āĻ˛ā§āϝāĻžā§ŸāύāĻ•āρāϤ āĻāĻ•ā§āϏāĻĒā§āϰ⧇āĻļāύ⧇āϰ āϞāϜāĻŋāĻ•ā§āϝāĻžāϞ āĻŽāĻžāύ⧇āϰ āωāĻĒāϰ āύāĻŋāĻ°ā§āĻŦāϰāĻļā§€āϞ āĻĻ⧁āχāϟāĻŋ āϏāĻŽā§āĻ­āĻžāĻŦā§āϝ āĻĢāĻžāĻ‚āĻļāύ āĻĢāϞāĻžāĻĢāϞ⧇āϰ āĻŽāĻ§ā§āϝ⧇ āĻāĻ•āϟāĻŋ āĻĒā§āϰāĻĻāĻžāύ āĻ•āϰ⧇ āĻĨāĻžāϕ⧇āĨ¤

Syntax:


IIf (Expression, ExpressionTrue, ExpressionFalse)

Parameters:

āĻāĻ•ā§āϏāĻĒā§āϰ⧇āĻļāύ: āϝ⧇āϕ⧋āύ⧋ āĻāĻ•ā§āϏāĻĒā§āϰ⧇āĻļāύ āφāĻĒāύāĻŋ āϝāĻž āĻŽā§‚āĻ˛ā§āϝāĻžā§Ÿāύ āĻ•āϰāϤ⧇ āϚāĻžāύāĨ¤ āϝāĻĻāĻŋ āĻāĻ•ā§āϏāĻĒā§āϰ⧇āĻļāύāϟāĻŋ True āĻšāĻŋāϏ⧇āĻŦ⧇ āĻŽā§‚āĻ˛ā§āϝāĻžā§ŸāĻŋāϤ āĻšā§Ÿ, āϤāĻžāĻšāϞ⧇ āĻĢāĻžāĻ‚āĻļāύāϟāĻŋ ExpressionTrue āĻāϰ āĻĢāϞāĻžāĻĢāϞ āĻĒā§āϰāĻĻāĻžāύ āĻ•āϰ⧇ āĻĨāĻžāϕ⧋, āĻ…āĻ¨ā§āϝāĻĨāĻžā§Ÿ āĻāϟāĻŋ ExpressionFalse āĻāϰ āĻĢāϞāĻžāĻĢāϞ āĻĒā§āϰāĻĻāĻžāύ āĻ•āϰ⧇ āĻĨāĻžāϕ⧇āĨ¤

ExpressionTrue, ExpressionFalse: āϝ⧇āϕ⧋āύ⧋ āĻāĻ•ā§āϏāĻĒā§āϰ⧇āĻļāύ, āϝāĻžāϰ āĻāĻ•āϟāĻŋ āϞāϜāĻŋāĻ•ā§āϝāĻžāϞ āĻŽā§‚āĻ˛ā§āϝāĻžā§Ÿāύ⧇āϰ āωāĻĒāϰ āύāĻŋāĻ°ā§āĻ­āϰ āĻ•āϰ⧇ āĻĢāĻžāĻ‚āĻļāύ āĻĢāϞāĻžāĻĢāϞ āĻšāĻŋāϏ⧇āĻŦ⧇ āĻĒā§āϰāĻĻāĻžāύ āĻ•āϰāĻž āĻšāĻŦ⧇āĨ¤

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 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

If or Select Case statements

Switch function