Set

Top  Previous 

Description

Assigns an object reference to a variable or property.

Syntax

Set objectvar = {objectexpression | Nothing}

Examples:

The following code illustrates how the FileSystemObject is used to return a TextStream object that can be read from or written to:

Private Sub CreateATestFile()

Dim fs, a

Set fs = CreateObject("Scripting.FileSystemObject")

Set a = fs.CreateTextFile("c:\testfile.txt", True)

a.WriteLine("This is a test.")

a.Close

'Do Cleanup

Set a = Nothing

Set fs = Nothing

End Sub

In the code shown above, the CreateObject function returns the FileSystemObject (fs). The CreateTextFile method then creates the file as a TextStream object (a) and the WriteLine method writes a line of text to the created text file. The Close method flushes the buffer and closes the file.

The following code illustrates how to create and use a CommandoXML Object:

Private Sub CreateXMLFile()

Dim oXML, ndRoot, ndChild

Dim sBuff

sBuff = "<MYXML></MYXML>"

Set oXML = oUTILITIES.CommandoXMLObject()

With oXML

   .OpenFromString sBuff

   Set ndRoot = .GetRootElement()

   .SetAttribute ndRoot, "MYNAME", "John Q. Public"

   'Add a Child Node

   sBuff = "<CHILD></CHILD>"

   Set ndChild = .XMLAddNode(ndRoot, sBuff)

   .SetAttribute ndChild, "NAME", "John Q. Public Jr."

   .SetAttribute ndChild, "AGE", 6

   MsgBox .XML, VBINFORMATION, "The XML"

   .Save oUTILITIES.OutputFolder & "Test.XML"

   'Do Cleanup

   Set ndChild = Nothing

   Set ndRoot = Nothing

   Set oXML = Nothing

End With

 

End Sub