IsNull 函数IsNull function

返回指示表达式是否包含无效数据 (Null) 的 Boolean 值。Returns a Boolean value that indicates whether an expression contains no valid data (Null).



必需的_expression_ 参数是一个包含数值表达式字符串表达式VariantThe required expression argument is a Variant containing a numeric expression or a string expression.


如果 expressionNull,则 IsNull 将返回 True;否则 IsNull 将返回 FalseIsNull returns True if expression is Null; otherwise, IsNull returns False. 如果 expression 由多个变量组成,则任何成员变量中的 Null 将导致为整个表达式返回 TrueIf expression consists of more than one variable, Null in any constituent variable causes True to be returned for the entire expression.

Null 值指示 Variant 未包含任何有效数据。The Null value indicates that the Variant contains no valid data. NullEmpty 不同,其指示尚未初始化变量。Null is not the same as Empty, which indicates that a variable has not yet been initialized. 它与有时称为空字符串的零长度字符串 ("") 也不同。It is also not the same as a zero-length string (""), which is sometimes referred to as a null string.


[!重要信息] 使用 IsNull 函数可确定表达式是否包含 Null 值。Use the IsNull function to determine whether an expression contains a Null value. 有些情况下,您可能希望计算结果为 True 的表达式,如 If Var = NullIf Var <> Null 始终为 FalseExpressions that you might expect to evaluate to True under some circumstances, such as If Var = Null and If Var <> Null, are always False. 这是因为包含null的任何表达式本身为null , 因此为FalseThis is because any expression containing a Null is itself Null and therefore False.


此示例使用 IsNull 函数确定变量是否包含 NullThis example uses the IsNull function to determine if a variable contains a Null.

Dim MyVar, MyCheck
MyCheck = IsNull(MyVar)    ' Returns False.

MyVar = ""
MyCheck = IsNull(MyVar)    ' Returns False.

MyVar = Null
MyCheck = IsNull(MyVar)    ' Returns True.

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.