IIf Function

返回两个可能的函数结果之一,具体是哪一个结果取决于对表达式进行求值后得到的逻辑值。

语法:


IIf (Expression, ExpressionTrue, ExpressionFalse)

参数:

Expression: 要求值的任意表达式。如果对表达式求值的结果为 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.


错误代码:

5 无效的过程调用

示例:


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

请支持我们!