6 Replies Latest reply on Mar 18, 2015 5:13 PM by aksnk89

    ProcessBook Button properties help.


      Hi ,

      Is there any way we can capture the working status of the button is ProcessBook via VBA i.e Button "Target Found" or "Target not Found " something like this.

      The idea here is we have huge number of PDI files and checking whether links are working or not working is a very tedious task . Can anyone help me in find such property for button ?


      Here, in the image you can see "Target Found" i want to capture this text and based on this will get to know which links are working and which are not .


      Thanks in Advance .



      Regards ,


        • Re: ProcessBook Button properties help.
          Eugene Lee

          Hi Akash,


          Rather than seeking to do that, if what you want is to identify all buttons with broken links, you can loops through the buttons collection and invoke the Execute method. If the link is broken, then an error will be thrown. In the error handler, you can then change the name of the button to something like 'error' to help you identify those buttons with broken links. Thanks!

          • Re: ProcessBook Button properties help.

            Hello Akash,


            I believe this is possible to do, and I have prepared a code example where you can determine if the action string ( that is the file path ) is valid for a button which has specific action of opening another display.

            You may either, repair the buttons action using code or output results to a text file.

            This involves that you "copy paste" this code into each display that you want to "verify/repair" and that you execute the Sub FindBrokenButtonLinks.



            ' Module    : Module1
            ' Purpose   : Shows how to find buttons, and check if their actions point to a valid
            '             PDI file.
            ' For more information about manipulating buttons please see: PI ProcessBook VBA Language Reference P.303
            ' https://techsupport.osisoft.com/Downloads/File/0c9043dd-a7a3-4b49-8b62-c8f408d61c6f
            ' Procedure : FindBrokenButtonLinks
            ' Purpose   : Look within all buttons of a display and report if links are broken
            '             code could be added to repair the action string or
            '             you can uncomment the line that output results to a text file (c:\temp\logs.txt)
            Public Sub FindBrokenButtonLinks()
                Dim mSymbol As Symbol
                '  Loops through all symbols on the display
                For Each mSymbol In ThisDisplay.Symbols
                    ' check if the symbol is a button
                    If mSymbol.Type = pbSymbolButton Then
                        Dim objButton As Button
                        Dim objButtonDef As ButtonDefinition
                        Set objButton = mSymbol
                        Set objButtonDef = objButton.GetDefinition()
                        ' Check if button is configured to open a PDI
                        ' Note: it may be that all cases are not covered by this condition
                        '       since it was testes in a limited environment.
                        If objButtonDef.Type = pbButLinkedPDI Then
                            Dim exists As Boolean, path As String
                            path = Replace(objButtonDef.Action, """", "")
                            exists = FileExists(path)
                            Debug.Print "Button Text: " & objButtonDef.Text, "Button Action:" & objButtonDef.Action, "File Exists?:" & exists, "FilePathChecked: " & path
                            ' here you could output same data into a text file instead, to generate some sort of a reporting
                            ' here is an example, just uncomment the following line and DONT FORGET TO CHANGE THE logfile PATH if you do!:
                            ' Write2File "Button Text: " & objButtonDef.Text & " Button Action:" & objButtonDef.Action & " File Exists?:" & exists & " FilePathChecked: " & path, "c:\temp\logs.txt"
                            If (Not exists) Then
                                ' your logic to fix the action if the file does not exist here...
                                ' ex:
                                ' write the new action value into the button definition
                                ' objButtonDef.Action = "c:\newFile.pdi"
                                ' update the button definition
                                ' objButton.SetDefinition objButtonDef
                            End If
                        End If
                    End If
            End Sub
            ' Procedure : FileExists
            ' Purpose   : Check if a file exists
            Public Function FileExists(path As String) As Boolean
                If Dir(path) <> "" Then
                    FileExists = True
                    FileExists = False
                End If
            End Function
            ' Procedure : Write2File
            ' Author    : Patrice
            ' Date      : 2009-07-08
            ' Purpose   : Write one line to a file
            Public Function Write2File(ToWrite As String, FileName As String) As Boolean
                On Error GoTo Err:
                Open FileName For Output As #1
                Print #1, ToWrite
                Close #1
                Write2File = True
                Exit Function
                Debug.Print "Error # " & Err.Number & " " & Err.Description
                Write2File = False
            End Function



            Please let me know how it works for you and I hope this helps you.

            • Re: ProcessBook Button properties help.

              Thanks Lee and Patrice , with your suggestions i could develop a tool that would find error linked buttons for all the PDI files in the specified folder.