3 Replies Latest reply on May 31, 2018 9:41 AM by Muthulingam-EnQuest

    What is the VBA Code to return a Set of Specific Tags with a specific Keyword into a List Box in PI ProcessBook?

    Muthulingam-EnQuest

      Hi guys,

       

      I need a VBA Code to return a Set of Specific Tags with a specific Keyword into a List Box in PI ProcessBook.

      I would like to create a Check Box in PI ProcessBook.

      When the Check Box is checked it returns a Set of PI Tags/ Points with a certain Keyword in the Description  into a List Box.

       

      For Example:

      Lets say I have marked 100 Tags out of 6,000 Tags with the following Keyword  "Well Parameter" in the Description.

      I want the VBA Code to return all the 100 Tags (with the Tag Description) with the specific Keyword mentioned above.

      I can't find it in the PI ProcessBook Programmer's Guide.

       

      Use Case:

      - to display the Tag Name and Tag Description in the List box

      - This list can later be used by End users to generate Trends

       

      I found this Code from Patrice Thivierge (Thanks Patrice):

       

      Procedure : TagSearch 

      ' Purpose   : Opens the Tag Search dialog and print the selected tags into 

      ' the Immediate Window (Crtl+G) 

      '--------------------------------------------------------------------------------------- 

      Public Sub TagSearch() 

          Dim search As New PISDKDlg.TagSearch 

          Dim selectedPoints As PointList 

       

       

          Set selectedPoints = search.Show 

       

       

          Dim point As PIPoint 

          Dim p As Variant 

          For Each p In selectedPoints 

              Set point = p 

              Debug.Print point.name 

          Next 

       

       

      End Sub

       

      I just need the Tag Keyword Search VBA Code

       

      Best regards,

       

      Muthulingam Ramiah

       

      Ganesh Supromaniam

      Patrice Thivierge

        • Re: What is the VBA Code to return a Set of Specific Tags with a specific Keyword into a List Box in PI ProcessBook?
          mshimko

          Hello, Muthulingam.

           

          You can achieve this a few ways, depending on how much control you want the users to have over their search. If you'd like them to be able to search on other tag attributes in addition to the Descriptor, then I would recommend using a variation of Patrice's code sample above. If users should only ever search for keywords in the Descriptor field and all of the tags with the keyword should automatically be selected, then you should use the GetPointsSQL PI SDK method. Find the two VBA functions below for both situations:

           

          Sub GetPointsByDescMask(desc_mask As String)
              'Get tag list from Descriptor mask
              
              Dim ptlist As PointList
              Dim pt As PIPoint
              
              Set ptlist = PISDK.Servers.DefaultServer.GetPointsSQL("Descriptor Like '" & desc_mask & "'")
                 
              'Add points list to drop-down list
              ThisDisplay.tagResults.List = Array()
              For Each pt In ptlist
                  ThisDisplay.tagResults.AddItem pt.Name
              Next pt
              
          End Sub
          
          Sub GetPointsBySearchDialog()
              'Get tag list from tag search
              
              Dim ptlist As PointList
              Dim pt As PIPoint
              Dim search As New PISDKDlg.TagSearch
              
              'Get points from the search dialogs
              Set ptlist = search.Show
              
              'Add points list to drop-down list
              ThisDisplay.tagResults.List = Array()
              For Each pt In ptlist
                  ThisDisplay.tagResults.AddItem pt.Name
              Next pt
              
          End Sub
          
          
          
          
          

           

          For both methods, you'll need a ComboBox on the display (mine is named tagResults) to store the search results and a Search button to call the method.

           

          For GetPointsByDescMask, you'll also need a text box on the display that stores the keyword (mine is named search_mask). When you press the Search button to call the method, you can extract the contents of the text box and pass it to GetPointsByDescMask:

           

          Sub getpoints_Click()
              ThisDisplay.GetPointsByDescMask ThisDisplay.search_mask.Text
          End Sub
          
          

           

          Here is a screenshot of my display using the GetPointsByDescMask method:

           

          -Mike

          4 of 4 people found this helpful