Use Automation Objects

Create node objects, select processes, and select statistics using automation objects.

This topic explains how to use the node factory and nodes, select statistics, and select Processes. The Connect:Direct® automation objects use late binding, so you must dimension your variables as type Object.

Create Node Objects

The Connect:Direct node factory creates node objects. These node objects serve as virtual servers and represent a connection to a Connect:Direct server (node).

To obtain a connection (and therefore a node), you must use the node factory. Create the node factory using the ProgID CD.NodeFactory:

Dim factory as Object
 Set factory = CreateObject (“CD.NodeFactory”)
To determine the node you want to connect to, set the properties of the factory object. Next, call CreateNode to connect to the node. If the connection is successful, a node object returns. Otherwise, an error is thrown indicating the cause of the problem.
factory.NodeName = “CD.Node1"
 factory.UserId = “user1"
 factory.Password = “password”
 {
 Dim node as Object
 Set node = factory.CreateNode()
The node name refers to the name used by the Client Connection Utility. You must set up the nodes that you want to connect to using the Client Connection Utility prior to using the Connect:Direct SDK.

Node Usage

The node object represents the connection to a Connect:Direct node. Using the node enables you to select statistics or Processes.

Select Processes

To select Processes, you must first format a select Process command and pass it to the SelectProc method. The records return as Process objects and are stored in the ProcCollection container. Because a background thread populates the collection, it is returned to the caller before it is completely filled. Therefore, the only access method available is using the For Each construct.
Note: The usual Count property is not available because the count is not known until all records are returned.
 Dim procs as Object ; the process collection 
 Dim proc as Object ; each process record 
 Set procs = node.SelectProc ("SELECT PROCESS ") 
 For Each proc in procs 
     Debug.Print proc.ProcessName 
 Next proc

Select Statistics

To select statistics records, you must format a select statistics command and pass it on to the SelectStats method of the node. The records return as Statistic objects stored in a StatCollection container. Because a background thread populates the collection, it returns to the caller before it is completely filled. Therefore, the only access method available is using the For Each construct.

Note: The usual Count property is not available because the count is not known until all records are returned.
 Dim stats as object ; the Statistics collection 
 Dim stat as Object ; each statistic record 
 Set stats = node.SelectStats ("SELECT STATISTICS") 
 For Each stat in stats 
     Debug.Print stat.RecId 
 Next stat

Because the server can send records slowly, the interface can be jerky while reading records. Because records are read using a background thread, it useful to select the statistics before time-consuming tasks like constructing windows. This method enables the server to send records in background.

Automation Class Errors

The automation classes use the standard Visual Basic error-handling mechanism. When an error is raised in an automation object, no real value is returned from the function. For example, if an error is raised in the node factory example in the Create an Object to connect to a Node topic (see related link below), the node does not have a value (it has the default value of nothing) because CreateNode has not returned anything.

When the Connect:Direct automation objects raise an error, they set the error number to a Connect:Direct SDK error value and store a description in the error text.