Aliases Example

 

 

This example displays the server aliases currently stored in the Known Servers Table in a list box. When an alias is selected from the list box, its corresponding server handle is displayed. The example allows adding new server aliases as well as removing existing ones. The bottom portion of the screen demonstrates looking up the server handle (name) associated with an entered server alias.

Build the Server Aliases example as follows:

1. Create a new project and add references to the PISDK libraries.

2. Add the visual elements as shown in the picture. Make sure the numbered element names (label1, list1, ...) match those shown.

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

Option Explicit

Private Sub Command1_Click()
On Error GoTo handler
  If Text1.Text = "" Then
    MsgBox "Please enter an alias for the new alias/handle pair"
    Exit Sub
  End If
  Servers.Aliases.Add Text1.Text, Combo1.Text
  DisplayAliases
Exit Sub
handler:
  MsgBox Err.Description
End Sub

Private Sub Command2_Click()
On Error GoTo handler
  If Text2.Text = "" Then
    MsgBox "Please enter an alias/ID whose " & _
      "handle/server you wish to determine."
    Exit Sub
  End If
  Dim serverhandle As String
  serverhandle = Servers.ResolveID(Text2.Text, True)
  Label10.Caption = serverhandle
Exit Sub
handler:
  MsgBox Err.Description
End Sub

Private Sub Command3_Click()
On Error GoTo handler
  If List1.Text = "" Then
    MsgBox "Please select an alias to remove"
  End If
  Servers.Aliases.Remove List1.Text
  DisplayAliases
Exit Sub
handler:
  MsgBox Err.Description
End Sub

Private Sub Form_Load()
On Error GoTo handler
  DisplayAliases
  ClearEntries
  LoadHandles
  If Combo1.ListCount > 0 Then
    Combo1.ListIndex = 0
  End If
Exit Sub
handler:
  MsgBox Err.Description
End Sub

Private Sub List1_Click()
Label4.Caption = List1.Text
Label5.Caption = Servers.Aliases(List1.Text)
End Sub

Private Sub DisplayAliases()
  Dim als As Variant
  List1.Clear
  For Each als In Servers.Aliases
    List1.AddItem als
  Next
End Sub
Private Sub ClearEntries()
Label4.Caption = ""
Label5.Caption = ""
Text1.Text = ""
Text2.Text = ""
Label10.Caption = ""
End Sub
Private Sub LoadHandles()
  Combo1.Clear
  Dim srv As Server
  For Each srv In Servers
    Combo1.AddItem srv.Name
  Next
End Sub
Enabling Operational Intelligence