例 1 (構文 1)
' The variable terPoint is an object reference variable of
' the class Point, which is already defined. The New sub for
' class Point has no arguments. Set creates a new object
' of the class Point and assigns its reference to terPoint.
Dim terPoint As Point
Set terPoint = New Point
例 2 (構文 2)
' The classes Worker and Carpenter must already be defined,
' with Carpenter as a derived class of Worker. The first Dim
' statement declares x as an object reference variable of
' Worker. The second Dim statement declares y as an object
' reference variable of Carpenter. This statement also creates
' a new object of Carpenter, named "Terry"; and assigns its
' reference to the variable y. The Set statement assigns the
' reference in y to variable x. (A reference to a Carpenter
' can be assigned to a variable of Worker because Worker
' is the base class of Carpenter.)
Dim x As Worker
Dim y As New Carpenter("Terry")
Set x = y
例 3 (構文 3)
' The Dim statement declares icCheckBox as an object reference
' variable of the pre-defined product class Check. The Set
' statement binds the object reference variable icCheckBox to
' the product object Checkbox1.
Dim icCheckBox As Check
Set icCheckBox = Bind("Checkbox1")