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

IsObject Function

Syntax

IsObject(varname)
varname

Use: Required

Data Type: Any

Name of the variable to be evaluated.

Return Value

Boolean (True or False).

Description

Indicates whether a variable contains a reference to an object—in other words, if it’s an object variable.

Rules at a Glance

If the variable passed to IsObject references or has referenced an object, even if its value is Nothing, True is returned; otherwise, IsObject returns False.

Programming Tips and Gotchas

  • IsObject doesn’t validate the reference being held by an object variable; it simply determines whether the variable is an object. To ensure that an object reference is valid, you can use the syntax Is Nothing, as shown in this code snippet:

    If objVar Is Nothing Then
    ...
    End if
  • IsObject is simply a “convenience” function that is roughly equivalent to the following user-defined function:

    Public Function IsObject(varObj)
    
    If VarType(varObj) = vbObject Then
       IsObject = True
    Else
       IsObject = False
    End If
    
    End Function

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