Dim oOPCWareX Dim iReturnedItemIndex(9) 'As Integer Dim sServerKey 'As String Dim iServerIndex 'As Integer Dim sGroupKey 'As String Dim iGroupIndex 'As Integer '------------------------------------------------------------ Set oOPCWareX = CreateObject("OPCWareAX.OPCWareX") LoadProgramatically '------------------------------------------------------------ ' This works for the default configuration, Group named "Test 1", ' writing to itemId BOOL.Out1 Dim iRet 'As Boolean Dim ValuesToRead(2) 'As Variant Dim ItemKeys(2) 'As Variant ItemKeys(1) = "SimulatePLC.BOOL.Out1" ItemKeys(2) = iReturnedItemIndex(9) '"Item 9", as per the ints returned when the items were added with oOPCWareX.AddNewItem iRet = oOPCWareX.ReadGroupSynchronous(iServerIndex, iGroupIndex, ItemKeys, ValuesToRead, 1) MsgBox "SimulatePLC.BOOL.Out1 = " & ValuesToRead(1) MsgBox "Item(9) = " & ValuesToRead(2) Set oOPCWareX = nothing '------------------------------------------------------------ Sub LoadProgramatically() 'On Error GoTo ErrorHandler ' ' The servers, groups and items below should only be added if previously configured ' via the GUI, so you know they exist and can be connected to. ' ' Normally you would first configure your servers etc through the GUI, then obtain ' the details from the SaveConfig ethod, and store the returned data in a database/file. ' 'SaveConfigINI ' ' Through your application you would retrieve the particular data of interest from ' the database/file and add servers, groups and items programatically as below ' ' Alternatively you can use the LoadConfig method. ' 'do this for all servers to add vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 'release the existing configuration oOPCWareX.DisconnectAll 'sServerKey = OPCWareX1.AddNewServer("ICONICS.Simulator.1", "") iServerIndex = oOPCWareX.AddNewServer("ICONICS.Simulator.1", "") sServerKey = "Server " & iServerIndex 'if iServerIndex = 0 connection failed, otherwise we can refer to the server by its index 'add groups to this server 'do this for all groups to add vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 'first group called "Test1" 'sGroupKey = OPCWareX1.AddNewGroup("Test1", 1000, 2, True, True, iSrvIndex) ' sGroupKey = "Group 1 0" iGroupIndex = oOPCWareX.AddNewGroup("Test1", 1000, 2, True, True, iServerIndex) ' sGroupKey = "Group 1 0" sGroupKey = "Group " & iGroupIndex & " " & iServerIndex Dim i 'As Integer 'now add the items to this group 'do this for all items to be added vvvvvvvvvvvvvvvvvvvvvvvv ' For i = 1 To 5 ' 'Debug.Print OPCWareX1.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.PHASED.Ramp" & i, 0, True) ' iReturnedItemIndex(i) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.PHASED.Ramp" & i, 0, True) ' Item1 ' Next i iReturnedItemIndex(1) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.PHASED.Ramp1", 0, True) ' Item1 iReturnedItemIndex(2) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.PHASED.Ramp2", 0, True) ' Item2 iReturnedItemIndex(3) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.PHASED.Ramp3", 0, True) ' Item3 iReturnedItemIndex(4) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.PHASED.Ramp4", 0, True) ' Item4 iReturnedItemIndex(5) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.PHASED.Ramp5", 0, True) ' Item5 iReturnedItemIndex(6) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.BOOL.In1", 0, True) ' Item6 iReturnedItemIndex(7) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.BOOL.In2", 0, True) ' Item7 iReturnedItemIndex(8) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.BOOL.Out1", 0, True) ' Item8 iReturnedItemIndex(9) = oOPCWareX.AddNewItem(iServerIndex, iGroupIndex, "SimulatePLC.BOOL.Out2", 0, True) ' Item9 'do this for all items to be added ^^^^^^^^^^^^^^^^^^^^^^^^ 'do this for all groups to add ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 'do this for all servers to add ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 'ErrorHandler: End Sub '------------------------------------------------------------