Set Statement
- Updated2024-09-12
- 1 minute(s) read
VBScript Language Directory > Objects and Classes > Set Statement
Set Statement
Use the Set statement to assign an object reference to a variable.
Set ObjectVar = ObjectExpression | New ClassName | Nothing
| ObjectVar | Name of the variable according to the standard conventions. |
| ObjectExpression | Expression that consists of an object name, another object variable, or a function or method that returns and object. . |
| New ClassName | Expression with which you create a new instance of the ClassName class. You can define a class using the Class statement. If ObjectVar already contains a reference to an object, this reference is released as soon as the new reference is assigned. |
| Nothing | Keyword that cancels the assignment of the object variables to the object. If there are no further references to this object, you also release the system resources and the memory resources. |
With the Dim statement, you declare one variable. If you want this variable to refer to an object, use the Set statement to create a reference to the object. You also can define several object variables that simultaneously refer to the same object. If you change the object, these changes always affect all variables that refer to this object.
The following example shows how you can generate an object of the FileSystemObject class, use it, and then release it:
Dim FSO, bExists Set FSO = CreateObject("Scripting.FileSystemObject") bExists = FSO.FileExists("C:\Autoexec.bat") Call MsgBox(bExists) ' further instructions Set FSO = Nothing