Servers Events, Example




This example shows how to handle events from the Servers collection.  It uses the PISDKDlg.Connections.ShowConnectionsDialog to provide a tool for easily manipulating the Known Servers Table.  As changes are made to the Known Servers Table, events are fired by the Servers collection and caught by the code shown, displaying Message Box dialogs for each event.


Build this Servers example as follows:

1. Create a new project and add a reference to the PISDK library. Also add a reference to the PI-SDK Dialogs library.

2. Add the visual elements as shown in the picture. 

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


Dim cnxn As PISDKDlg.Connections
Dim WithEvents EServers As PISDK.ServersEvents
Private Sub Command1_Click()
   Set cnxn = New PISDKDlg.Connections
   cnxn.ShowConnectionDialog False
End Sub
   Private Sub Form_Load()
      Set EServers = Servers.Events
   End Sub
   Private Sub EServers_OnAdd(ByVal Server As PISDK.Server)
      MsgBox Server.Name & " is now known to me."
   End Sub

   Private Sub EServers_OnRemove(ByVal Server As PISDK.Server)
      MsgBox Server.Name & " is no longer known to me."
   End Sub
   Private Sub EServers_OnNewDefault(ByVal OldDefault As PISDK.Server)
      MsgBox Servers.DefaultServer.Name & " is now the default Server " _
          & vbCrLf & "The previous default server was " & OldDefault.Name
   End Sub
   Private Sub EServers_OnOpen(ByVal Server As PISDK.Server, ByVal NewUser As String)
      MsgBox NewUser & " logged in to server " & Server.Name
   End Sub
   Private Sub EServers_OnClose(ByVal Server As PISDK.Server, ByVal OldUser As String)
      MsgBox OldUser & " logged out from server " & Server.Name
   End Sub
   Private Sub EServers_OnEdit(ByVal Server As PISDK.Server, _
               ByVal OldProperties As NamedValues, _
               ByVal NewProperties As NamedValues)
      MsgBox Server.Name & "." & OldProperties(1).Name & " edited:" _
                & vbCrLf & " value was " & OldProperties(1).Value & _
                ", is now " & NewProperties(1).Value
   End Sub
Enabling Operational Intelligence