Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

VBScript Set Statement

Assigns an object reference to a variable or property.

Syntax: VBScript Set Statement

Set objectvar = {objectexpression | Nothing}

Arguments: VBScript Set Statement

objectvar

The name of the variable or property; follows standard variable naming conventions.

objectexpression

An expression consisting 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: VBScript Set Statement

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

The Dim, Private, Public, or ReDim statements only declare a variable that refers to an object. No actual object is referred to until you use the Set statement to assign a specific object.

Generally, when you use Set to assign an object reference to a variable, no copy of the object is created for that variable. Instead, a reference to the object is created. More than one object variable can refer to the same object. Because these variables are references to (rather than copies of) the object, any change in the object is reflected in all variables that refer to it.

Function ShowFreeSpace(drvPath)

   Dim fso, d, s

   Set fso = CreateObject("Scripting.FileSystemObject")

   Set d = fso.GetDrive(fso.GetDriveName(drvPath))

   s = "Drive " & UCase(drvPath) & " - "

   s = s & d.VolumeName & "<BR>"

   s = s & "Free Space: " & FormatNumber(d.FreeSpace/1024, 0)

   s = s & " Kbytes"

   ShowFreeSpace = s

End Function

Using the New keyword allows you to concurrently create an instance of a class and assign it to an object reference variable. The variable to which the instance of the class is being assigned must already have been declared with the Dim (or equivalent) statement.

Refer to the documentation for the GetRef function for information on using Set to associate a procedure with an event.

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.