IIf Function

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

Syntax:


IIf (Bool As Boolean, Variant1 As Variant, Variant2 As Variant) As Variant

Parameters:

Bool: Any expression that you want to evaluate. If the expression evaluates to True, the function returns the value of Variant1, otherwise it returns the value of Variant2.

Variant1, Variant2: Any expression, one of which will be returned as the function result, depending on the logical evaluation.

note

IIf evaluates both Variant1 and Variant2 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!