AttributeSets Example


This example, during the Form_Load, connects to the default server, and loads the list of the server's attribute sets in the ListBox List1. It also fills List 3 with a predefined set of attribute names that can be used to build a new attribute set.

When clicking any item in the first list, the Click event handler loads the specific attributes for the selected set into List2. Hitting Command1 adds a new attribute set to the server named by the entry in the TextBox Text1 and containing the attributes selected from the Samples in List3. It first checks that a name has been entered and at least one attribute has been selected. If all goes well it reports the success of the add and redisplays the list of attribute sets for the server in List1.

Note you are not currently able to remove attribute sets from a server so exercise caution when using this example. It is best used on a development PI server.


Build the AttributeSets 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, ...) match those shown.

3. Set the MultiSelect property of List3 to 2 to support multiple selection.

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

Option Explicit
Private atrPossible(5) As Variant
Private nmPossible(5) As String
Dim srv As Server

Private Sub Command1_Click()
On Error GoTo handler
  If Text1.Text = "" Then
    MsgBox "Please enter a name for the new attribute set."
    Exit Sub
  End If
  ' Get the selections
  Dim indx As Integer
  indx = 0
  If List3.SelCount <= 0 Then
    MsgBox "Please select one or more Sample Attributes" & _
      "to add to the new attribute set"
    Exit Sub
  End If
  ' We are all set, create a new named values collection for
  ' passing the selected new attributes to the AddSet call
  Dim nvAttrs As New NamedValues
  For indx = 0 To List3.ListCount - 1
    If List3.Selected(indx) Then
      ' Add this to our namedvalues collection
      nvAttrs.Add nmPossible(indx), atrPossible(indx)
    End If
  srv.AttributeSets.AddSet Text1.Text, nvAttrs
  MsgBox "Attribute Set successfully added"
Exit Sub
  MsgBox Err.Description
End Sub

Private Sub Form_Load()
  Set srv = Servers.DefaultServer
  Text1.Text = ""
End Sub
Private Sub DisplayAttrSets()
  Dim atrSet As PointAttributes
  For Each atrSet In srv.AttributeSets
    List1.AddItem atrSet.Name
  List1.ListIndex = 0
End Sub

Private Sub List1_Click()
  Dim atrSet As PointAttributes
  Set atrSet = srv.AttributeSets(List1.Text)
  Dim ptAtr As PointAttribute
  For Each ptAtr In atrSet
    List2.AddItem ptAtr.Name
End Sub
Private Sub InitPossible()
  atrPossible(0) = 1.25
  nmPossible(0) = "SomeFloat"
  atrPossible(1) = 6.75
  nmPossible(1) = "AnotherFloat"
  atrPossible(2) = "Default String"
  nmPossible(2) = "SomeString"
  atrPossible(3) = "Another Default String"
  nmPossible(3) = "AnotherString"
  atrPossible(4) = 1000
  nmPossible(4) = "SomeLong"
  Dim i As Integer
  For i = 0 To 4
    List3.AddItem nmPossible(i), i
End Sub

Enabling Operational Intelligence