GetObjectServers Example

 

This example shows how to find out what Server's are needed to restore the PIAlias's in a PIAliases collection of a PIModule.

When the button is clicked it will add a PIModule to the PIModule database of your default Server. It will add a PIAlias to the PIAliases collection of the module using the tag Sinusoid. Then it will get the IPIServers interface from the PIAliases collection and find out which servers are required to restore the PIAlias's in the collection.

 

Build the GetObjectServers example as follows:

1. Create a new project and add a reference to the PISDK Library.

2. Add one command button.

3. Cut and paste the code below into the project.

 

'
' This program shows how to find out what servers are needed to restore the PIAlias's in
' a PIAliases collection of a PIModule. When the button is clicked it will add a PIModule
' to the PIModule database of your default server. It will add a PIAlias to the PIAliases
' collection of the module using the tag Sinusoid. Then it will get the IPIServers interface
' from the PIAliases collection and find out which servers are required to restore the
' PIAlias's in the collection.
'
' 2002-Mar-27 KEC> Written
'
Option Explicit

Private Sub Command1_Click()
'
' This subroutine adds a module to the PIModule database root collection, adds an Alias to that module
' and gets the servers needed to restore the aliases in the PIAliases collection using the IPIServers interface
'
Dim myServer As Server ' get server once
Dim module As PIModule ' module added
Dim IPS As IPIServers ' IPIServers interface
Dim aliases As PIAliases ' PIAliases collection
Dim modName As String ' module name
Dim curDate As Date ' date used to generate unique module name
Dim sinTag As PIPoint ' Sinusoid tag
Dim serversCol As NamedValues ' servers collection
Dim myErrors As PIErrors ' errors collection

Set myServer = PISDK.Servers.DefaultServer
curDate = Now
modName = "IPIServers" & "_" & Format(curDate, "h:m:s") ' generate unique name for module to add
Set module = myServer.PIModuleDB.PIModules.Add(modName)
Set sinTag = myServer.PIPoints.Item("Sinusoid")
Set aliases = module.PIAliases
aliases.Add "SinTag", sinTag
'
' Alias has been added, get the servers collection from the PIAliases collection
'
Set IPS = aliases
Set serversCol = IPS.GetObjServers(myErrors)
'
' There should be only one server in there (myServer)
'
MsgBox "First server used by tags in PIAliases collection: " & serversCol.Item(1)

End Sub




Enabling Operational Intelligence