PointClasses Example


This example, during the Form_Load, connects to the default server, and retrieves and displays the list of point classes on the server in ListBox List1. It then retrieves and displays the list of attribute sets on the server in List3. When a point class is selected from List1, it retrieves the constituent attribute sets and displays them in List2 during the Click event.

When Command1 is hit it checks for an entered point class name and that at least one attribute set has been selected from List3. It builds an array of the selected attribute set names then calls PointClasses.Add to create the new point class.

As new PointClasses can not yet be deleted, care should be exercised when using this example. It is best run against a development PI system.


Build the PointClasses example as follows:

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

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

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

Option Explicit
Dim srv As Server

Private Sub Command1_Click()
Dim nmAtrSets() As String
On Error GoTo handler
  If Text1.Text = "" Then
    MsgBox "Please enter a name for the new PointClass"
    Exit Sub
  End If
  If List3.SelCount <= 0 Then
    MsgBox "Please select one or more attribute sets to " & _
      "make up the new PointClass"
    Exit Sub
  End If
  ' Now that we have input, build the array of attribute sets
  ' to pass to PointClasses.Add
  ReDim nmattrsets(List3.SelCount - 1) As String
  Dim indx As Integer
  Dim arrIndx As Integer
  arrIndx = 0
  For indx = 0 To List3.ListCount - 1
    If List3.Selected(indx) Then
      nmattrsets(arrIndx) = List3.List(indx)
      arrIndx = arrIndx + 1
    End If
  srv.PointClasses.Add Text1.Text, nmattrsets
  MsgBox "Point Class successfully added"
Exit Sub
  MsgBox Err.Description
End Sub

Private Sub Form_Load()
  Set srv = Servers.DefaultServer
  Text1.Text = ""
End Sub
Private Sub DisplayPointClasses()
  Dim ptcls As PointClass
  For Each ptcls In srv.PointClasses
    List1.AddItem ptcls.Name
End Sub

Private Sub List1_Click()
Dim atrset As PointAttributes
For Each atrset In srv.PointClasses(List1.Text).AttributeSets
  List2.AddItem atrset.Name
End Sub
Private Sub DisplayAttributeSets()
  Dim atrset As PointAttributes
  For Each atrset In srv.AttributeSets
    List3.AddItem atrset.Name
End Sub
Enabling Operational Intelligence