Share via


IsNothing 函式

更新:2007 年 11 月

傳回的 Boolean 值將說明運算式是否沒有指派的物件。

Public Function IsNothing(ByVal Expression As Object) As Boolean

參數

  • Expression
    必要項。Object 運算式。

備註

如果運算式代表目前沒有指派物件的物件變數,IsNothing 會傳回 True,否則會傳回 False。

IsNothing 是用來處理參考型別 (Reference Type)。實值型別不能保存 Nothing 的值,而且如果將 Nothing 指派給它,它會回復成預設值。如果在 Expression 中提供實值型別,則 IsNothing 一律會傳回 False。

範例

下列範例使用 IsNothing 函式,判斷物件變數是否與任何物件執行個體 (Instance) 相關聯。

Dim testVar As Object
' No instance has been assigned to variable testVar yet.
Dim testCheck As Boolean
' The following call returns True.
testCheck = IsNothing(testVar)
' Assign a string instance to variable testVar.
testVar = "ABCDEF"
' The following call returns False.
testCheck = IsNothing(testVar)
' Disassociate variable testVar from any instance.
testVar = Nothing
' The following call returns True.
testCheck = IsNothing(testVar)

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**Information

組件 (Assembly):Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

概念

實值型別和參考型別

參考

IsArray 函式 (Visual Basic)

IsDate 函式 (Visual Basic)

IsDBNull 函式

IsError 函式

IsNumeric 函式 (Visual Basic)

IsReference 函式

Object 資料型別

TypeName 函式 (Visual Basic)