O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Is Operator

Syntax

object1 Is object2
object1

Use: Required

Data Type: Object

An object variable.

object2

Use: Required

Data Type: 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 and object2 must be object references, or runtime error 424, “Object required,” results.

  • The operation returns a result of True if the object references are identical and False if they are not.

  • It is also possible to determine whether an object contains a valid reference by replacing object2 with the special Nothing keyword. For example:

    If oDrive Is Nothing Then

    returns True if oDrive does not refer to an object and False if it does. This should be used to test for an uninitialized object reference.

Programming Tips and Gotchas

  • Note that objects in VBScript are references—that is, they reference an object in memory. This means that if two variables reference 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 property values; a test for equal values is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required