PIHeadingSets/ PIHeadingSet / PIHeadings / PIHeading Example

Private Sub Command1_Click()
   BuildTaxonomyHeadingSet
   LoadPIHeadingSets
End Sub
  
Private Sub LoadPIHeadingSets()
  
   Dim HeadingSets As PIHeadingSets
   Dim HeadingSet As PIHeadingSet
   Dim mItem As ListItem
  
   Servers.DefaultServer.Open
   ListView1.ListItems.Clear
   ListView1.ColumnHeaders.Clear
   ListView1.ColumnHeaders.Add , , "Name", ListView2.Width * 4 / 16
   ListView1.ColumnHeaders.Add , , "Description", ListView2.Width * 5 / 16
   ListView1.ColumnHeaders.Add , , "Unique ID", ListView2.Width * 6 / 16
   ListView1.View = lvwReport
  
   Set HeadingSets = Servers.DefaultServer.PIModuleDB.PIHeadingSets
   For Each HeadingSet In HeadingSets
      Set mItem = ListView1.ListItems.Add
      mItem.Text = HeadingSet.Name
      mItem.SubItems(1) = HeadingSet.Description
      mItem.SubItems(2) = HeadingSet.UniqueID
      MsgBox "Ready to Display PIHeadings for " & HeadingSet.Name
      LoadPIHeadings HeadingSet.PIHeadings
   Next HeadingSet
End Sub
  
Private Sub LoadPIHeadings(Headings As PIHeadings)
  
   Dim Heading As PIHeading
   Dim mItem As ListItem
  
   Servers.DefaultServer.Open
   ListView2.ListItems.Clear
   ListView2.ColumnHeaders.Clear
   ListView2.ColumnHeaders.Add , , "Name", ListView2.Width * 3 / 16
   ListView2.ColumnHeaders.Add , , "Level", ListView2.Width * 2 / 16
   ListView2.ColumnHeaders.Add , , "Description", ListView2.Width * 5 / 16
   ListView2.ColumnHeaders.Add , , "Unique ID", ListView2.Width * 6 / 16
   ListView2.View = lvwReport
  
   For Each Heading In Headings
      Set mItem = ListView2.ListItems.Add
      mItem.Text = Heading.Name
      mItem.SubItems(1) = Heading.Level
      mItem.SubItems(2) = Heading.Description
      mItem.SubItems(3) = Heading.UniqueID
   Next Heading
End Sub
  
Private Sub BuildTaxonomyHeadingSet()
  
   Dim Heading As PIHeading
   Dim HeadingSet As PIHeadingSet
  
   Servers.DefaultServer.Open
   On Error Resume Next
   Set HeadingSet = Servers.DefaultServer.PIModuleDB.PIHeadingSets.Item("Taxonomy")
   If HeadingSet Is Nothing Then
      On Error GoTo 0
      Set HeadingSet = Servers.DefaultServer.PIModuleDB.PIHeadingSets.Add("Taxonomy", "Hierarchy of Life")
      Set Heading = HeadingSet.PIHeadings.Add("Kingdom", "First", 1)
      Set Heading = HeadingSet.PIHeadings.Add("Phylum", "Second", 2)
      Set Heading = HeadingSet.PIHeadings.Add("Class", "Third", 3)
      Set Heading = HeadingSet.PIHeadings.Add("Order", "Fourth", 4)
      Set Heading = HeadingSet.PIHeadings.Add("Family", "Fifth", 5)
      Set Heading = HeadingSet.PIHeadings.Add("Genus", "Sixth", 6)
      Set Heading = HeadingSet.PIHeadings.Add("Species", "Seventh", 7)
   Else
      On Error GoTo 0
   End If
End Sub
Enabling Operational Intelligence