Name

Set Statement

Syntax 1

Set objectvar = {[objectexpression | newclassname1 Nothing}
objectvar

Use: Required

Data Subtype: Object

The name of the object variable or property.

objectexpression

Use: Optional

Data Subtype: Object

An expression evaluating to an object.

new

Use: Optional

Type: Keyword

Creates a new instance of an object defined using the Class...End Class construct.

classname

Use: Required

Data Subtype: String literal

The name of the class defined by the Class...End Class construct to be instantiated.

Nothing

Use: Optional

Type: Keyword

Assigns the special datatype Nothing to objectvar, thereby releasing the reference to the object.

Syntax 2

Set object.eventname = GetRef(procname)
object.eventname

Use: Required

Type: Event

The name of an object event that, when fired, causes the code in procname to execute.

procname

Use: Required

Type: String literal

The name of the procedure that serves as the event handler for object.eventname.

Description

Assigns an object reference to a variable or property. Its second syntax, using the GetRef function defines an event handler for an event; this is discussed in the GetRef function entry.

Rules at a Glance

  • objectvar doesn’t hold a copy of the underlying object; it simply holds a reference to (that is, the address of) the object.

  • If the New keyword is used, a new instance of the class is immediately created and its Class Initialize event fires. This applies only to classes defined using the Class...End Class construct.

  • All classes defined by the

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.