Scripting > UNICOM Intelligence Function Library > Miscellaneous functions > CreateObject
 
CreateObject
Creates and returns a reference to an Automation object.
Syntax
CreateObject(Class)
Parameters
Class
Type: Text
The COM class name of the object to be created.
(return)
Type: Object
The created object.
Remarks
If the object cannot be created, an error occurs.
Example
The following mrScriptBasic example uses the CreateObject function as follows:
Line 5. The CreateObject function is used to create a DataLinkHelper object so that the DisplayWizard method can be used to display the Data Link Properties dialog box. See Displaying the Data Link Properties dialog box for more information.
Line 12. The CreateObject function is used to create an ADO Connection object, which is then used to open a connection to the data source and to return a recordset by executing a query against VDATA.
Line 17. The CreateObject function is used to create a Word Application object, so that the recordset can be inserted into a Word document.
Dim Wizard, ConnectionString, wordApp, wordDoc

' Use the Display wizard to open the Data Link Properties
' dialog box to get the connection string
Set Wizard = CreateObject("mrOleDB.DataLinkHelper") ' Line 5
ConnectionString = Wizard.DisplayWizard()

If Len(ConnectionString) > 0 Then
' Create a connection and use it to create a recordset
' by executing a query against VDATA
Dim adoConnection, adoRS
Set adoConnection = CreateObject("ADODB.Connection") ' Line 12
adoConnection.Open(ConnectionString)
Set adoRS = adoConnection.Execute("SELECT age, gender FROM VDATA WHERE Serial < 10")

' Copy the recordset into Word
Set wordApp = CreateObject("Word.Application") ' Line 17
wordApp.Visible = true
Set wordDoc = wordApp.Documents.Add()
wordDoc.ActiveWindow.Selection.Text = adoRS.GetString()
End if
See also
IIf
Miscellaneous functions