CreateObject() |
Top Previous Next |
In addition to the built-in objects that are passed to you by Commando, you can also create your own objects by using the CreateObject() function CreateObject - Creates a system object Description Use the CreateObject() function to create system objects like FileSystem objects, MSXML objects, ADO Connections, Recordsets, Streams object = CreateObject("<objectname.classname>") Returns an object or generates an error Example 1: Creating an ADO Connection object Dim myObj Set myObj = CreateObject("ADODB.Connection")
Example 2: Creating a file system object 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 |