Set

This statement assigns an object reference to a variable or property.

Syntax

Set objectvar = {objectexpression | Nothing}

Parameters

objectvar
Name of the variable or property; follows standard variable naming conventions.
objectexpression
Expression that consists of the name of an object, another declared variable of the same object type, or a function or method that returns an object of the same object type.
Nothing
Discontinues association of objectvar with any specific object. Assigning objectvar to Nothing releases all the system and memory resources associated with the previously referenced object when no other variable refers to it.

Remarks

To be valid, objectvar must be an object type consistent with the object being assigned to it.

Generally, when you use Set to assign an object reference to a variable, Visual Basic does not copy the object for that variable. Instead, Visual Basic creates a reference to the object. More than one object variable can refer to the same object. Because these variables are references to, rather than copies of, the object, changes to the object are reflected in each variable that refers to it.