IIf Function

αžαŸ’αžšαž‘αž”αŸ‹β€‹β€‹αž›αž‘αŸ’αž’αž•αž›β€‹β€‹αž’αž“αž»αž‚αž˜αž“αŸβ€‹β€‹αžŠαŸ‚αž›β€‹αž’αžΆαž…β€‹αžŠαŸ‚β€‹αž›β€‹αž’αžΆαž…β€‹αž€αžΎαžβ€‹αž‘αžΎαž„β€‹β€‹αž˜αž½αž™β€‹αž“αŸƒαž’αž“αž»αž‚αž˜αž“αŸβ€‹β€‹αž–αžΈαžš αž’αžΆαžŸαŸ’αžšαŸαž™β€‹αž›αžΎβ€‹αžαž˜αŸ’αž›αŸƒβ€‹αžαž€αŸ’αž€β€‹αžœαž·αž‡αŸ’αž‡αžΆβ€‹αž“αŸƒβ€‹αž€αž“αŸ’αžŸαŸ„αž˜β€‹αžŠαŸ‚αž›β€‹αž”αžΆαž“β€‹αžœαžΆαž™β€‹αžαž˜αŸ’αž›αŸƒΒ αŸ”

Syntax:


IIf (Expression, ExpressionTrue, ExpressionFalse)

Parameters:

Expression αŸ– αž€αž“αŸ’αžŸαŸ„αž˜αž˜αž½αž™β€‹αž…αŸ†αž“αž½αž“β€‹ αžŠαŸ‚αž›β€‹αž’αŸ’αž“αž€β€‹αž…αž„αŸ‹β€‹αžœαžΆαž™β€‹αžαž˜αŸ’αž›αŸƒΒ αŸ” αž”αŸ’αžšαžŸαž·αž“β€‹αž”αžΎβ€‹αž€αž“αŸ’αžŸαŸ„αž˜ αž–αž·αž αž’αž“αž»αž‚αž˜αž“αŸβ€‹αžαŸ’αžšαž‘αž”αŸ‹β€‹αž›αž‘αŸ’αž’αž•αž› 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 αž€αžΆαžšβ€‹αž αŸ…β€‹αž”αŸ‚αž”αž”αž‘β€‹αž˜αž·αž“β€‹αžαŸ’αžšαžΉαž˜αžαŸ’αžšαžΌαžœ

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

Please support us!