Name
Is Operator
Syntax
object1 Is object2
-
object1
Use: Required
Data Subtype: Object
An object variable.
-
object2
Use: Required
Data Subtype: Object
A second object variable.
Return Value
Boolean.
Description
Compares two object variables to determine whether they reference the same object.
Rules at a Glance
Both
object1
andobject2
must be object references, or runtime error 424, “Object required,” results.The operation returns a result of
True
if the object references are identical andFalse
if they are not.It is also possible to determine whether an object contains a valid reference by replacing
object2
with the specialNothing
keyword. For example:If oDrive Is Nothing Then
returns
True
ifoDrive
does not refer to an object andFalse
if it does. This should be used to test for an uninitialized object reference.
Programming Tips and Gotchas
Note that objects in VBScript are pointers—that is, they are variables that contain the address of the object that they reference. This means that if two variables point to the same object and you make changes to the object’s properties using the first object variable, those changes are reflected when you retrieve the object’s property settings using the second object variable.
You may wonder why there is a special
Is
operator for objects. When you perform a comparison of scalar variables, you want to know whether their values are the same. But in the case of objects, you want to know whether two references point to a single object. (Many objects have identical ...
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.