Sub LoadCommDriver()
'Declare variables
Dim NodeArray()
Dim oNode As Node
Dim bNode As Byte
Dim s As Byte
On Error GoTo ErrHandler
bNode = 0
With gProject
'Check the primary driver for incorrect or blank entry
If .Channels(1).PrimaryDriver = "" Or _
.Channels(1).PrimaryDriver = "None Loaded" Then
ReDim NodeArray(bNode)
'The driver cannot be changed if there are active nodes, so all active nodes
'must be temporarily disabled.
'Loop to step through each node in the Nodes collection
For Each oNode In .Nodes
'Check if the node is enabled. If it is, add its name to NodeArray so it can
'be re-enabled when we're finished. (This is done so only currently enabled
'nodes are re-enabled when the code is finished.)
If oNode.Enabled = True Then
ReDim Preserve NodeArray(UBound(NodeArray) + 1)
NodeArray(bNode) = oNode.Name
bNode = bNode + 1
'Disable the node and apply the change.
oNode.Enabled = False
oNode.WriteConfiguration
End If
Next
'Now the nodes are disabled and the driver can be changed.
.Channels(1).PrimaryDriver = "YOUR DRIVER NAME HERE"
'Apply the change
.Channels(1).WriteConfiguration
End If
End With
'Now re-enable all the nodes that were enabled and apply the changes
For s = LBound(NodeArray()) To (UBound(NodeArray()) - 1)
gNodes(NodeArray(s)).Enabled = True
gNodes(NodeArray(s)).WriteConfiguration
Next
'Done!
Exit Sub
ErrHandler:
MsgBox "An unexpected error has occurred in the LoadCommDriver subroutine.", vbCritical, "Error"
End Sub