Friday, March 11, 2022

Isobject function

Returns a Boolean value indicating whether an identifier (Visual Basic) represents an object variable.

Syntax

IsObject ( identifier )

The required identifierargument is a variable name.

Remarks

IsObject is useful only in determining whether a Variant is of VarTypevbObject. This could occur if the Variant actually references (or once referenced) an object, or if it contains Nothing.

IsObject returns True if identifier is a variable declared with object type or any valid class type, or if identifier is a Variant of VarTypevbObject, or a user-defined object; otherwise, it returns False. IsObject returns True even if the variable has been set to Nothing.

Use error trapping to be sure that an object reference is valid.

Example

Note: Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

This example uses the IsObject function to determine if an identifier represents an object variable. MyObject and YourObject are object variables of the same type. They are generic names used for illustration purposes only.

' Declare variables.
Dim MyInt As Integer, YourObject, MyCheck
Dim MyObject As Object
Set YourObject = MyObject ' Assign an object reference.
MyCheck = IsObject(YourObject) ' Returns True.
MyCheck = IsObject(MyInt) ' Returns False.

No comments:

Post a Comment