3 Replies Latest reply on Sep 5, 2017 8:03 PM by gmichaud-verreault

    Processbook VB update text with condition

    CarlosFelipe

      Hello, I need to set text of point tags value based on condition to be clear the Status in bulk, is there a less repetitive way to do it to several equipment's? Multi-state works as well, but will duplicate the need for get value from PI Data Archive.

       

      Private Sub Display_DataUpdate()

      Set server = PISDK.Servers.DefaultServer

      Set pt1 = server.PIPoints("BOILER-01A")

      Set pv1 = pt1.data.Snapshot

      Set pt2 = server.PIPoints("BOILER-02A")

      Set pv2 = pt2.data.Snapshot

      If pv1 >= 30 Then

          Status01A.LineColor = pbGreen

          Status01A.Contents = Format("Operating")

      Else

          Status01A.Contents = Format("Failure")

          Status01A.LineColor = pbRed

      End If

      If pv2 >= 30 Then

          Status02A.LineColor = pbGreen

          Status02A.Contents = Format("Operating")

      Else

          Status02A.Contents = Format("Failure")

          Status02A.LineColor = pbRed

      End If

      ... and so on.

      End Sub

        • Re: Processbook VB update text with condition
          pmartin

          Hi Carlos,

           

          You can simplify the program by throwing the bulk of this into a function.  If you wanted to take it a step further, you can put your tags and their associated Symbols in an array and loop through it.  Here's a quick example of the simple case:

           

          Dim server As PISDK.server
          
          Private Sub Display_DataUpdate()
              Update_Symbol "Sinusoid", ThisDisplay.Ellipse1
              Update_Symbol "CDT158", ThisDisplay.Ellipse2
          End Sub
          
          Private Sub Update_Symbol(TagName As String, Sym As Symbol)
              If server Is Nothing Then
                  Set server = PISDK.Servers.DefaultServer
              End If
             
              Set pt1 = server.PIPoints(TagName)
              Set pv1 = pt1.Data.Snapshot
              If pv1 >= 30 Then
                  Sym.LineColor = pbGreen
                  Sym.Contents = Format("Operating")
              Else
                  Sym.Contents = Format("Failure")
                  Sym.LineColor = pbRed
              End If
          End Sub
          
          Private Sub Display_Open()
              Set server = PISDK.Servers.DefaultServer
          End Sub
          
          1 of 1 people found this helpful
            • Re: Processbook VB update text with condition
              CarlosFelipe

              Thanks Paul, it worked very well, my "final" code is:

              Option Explicit

               

               

              Dim server As PISDK.server

              Dim TagVal As PIValue

               

              Private Sub Display_DataUpdate()

                  Update_Symbol "BOILER-01A", ThisDisplay.Status01A

                  Update_Symbol "BOILER-02A", ThisDisplay.Status02A

                  Update_Symbol "BOILER-03A", ThisDisplay.Status03A

                  Update_Symbol "BOILER-04A", ThisDisplay.Status04A

                 

                  Update_Symbol "BOILER-01B, ThisDisplay.Status01B

                  Update_Symbol "BOILER-02B, ThisDisplay.Status02B

                  Update_Symbol "BOILER-03B, ThisDisplay.Status03B

                  Update_Symbol "BOILER-04B, ThisDisplay.Status04B

                 

                  Update_Symbol "BOILER-01C, ThisDisplay.Status01C

                  Update_Symbol "BOILER-02C, ThisDisplay.Status02C

                  Update_Symbol "BOILER-03C, ThisDisplay.Status03C

                  Update_Symbol "BOILER-04C, ThisDisplay.Status04C

              End Sub

               

               

              Private Sub Update_Symbol(TagName As String, Sym As Symbol)

                  If server Is Nothing Then

                      Set server = PISDK.Servers.DefaultServer

                  End If

                

                  Set TagVal = server.PIPoints(TagName).data.Snapshot

                  If TagVal >= 30 Then

                      Sym.LineColor = pbGreen

                      Sym.Contents = Format("Operating")

                  Else

                      Sym.Contents = Format("Failure")

                      Sym.LineColor = pbRed

                  End If

              End Sub

               

              Private Sub Display_Open()

                  ThisDisplay.Width = 820

                  ThisDisplay.Height = 620

                  ThisDisplay.Zoom = 100

                  ThisDisplay.Maximize

                  data.Contents = FormatDateTime(Now)

                  Set server = PISDK.Servers.DefaultServer

              End Sub

                • Re: Processbook VB update text with condition
                  gmichaud-verreault

                  Thanks for providing your final code!

                  Just a formatting recommendation to make the code easier to read:

                       If you open the advanced editor then highlight your code -> ">>" -> Syntax Highlighting

                  Option Explicit
                  
                  
                  Dim server As PISDK.server
                  Dim TagVal As PIValue
                  
                  Private Sub Display_DataUpdate()
                      Update_Symbol "BOILER-01A", ThisDisplay.Status01A
                      Update_Symbol "BOILER-02A", ThisDisplay.Status02A
                      Update_Symbol "BOILER-03A", ThisDisplay.Status03A
                      Update_Symbol "BOILER-04A", ThisDisplay.Status04A
                     
                      Update_Symbol "BOILER-01B, ThisDisplay.Status01B
                      Update_Symbol "BOILER-02B, ThisDisplay.Status02B
                      Update_Symbol "BOILER-03B, ThisDisplay.Status03B
                      Update_Symbol "BOILER-04B, ThisDisplay.Status04B
                     
                      Update_Symbol "BOILER-01C, ThisDisplay.Status01C
                      Update_Symbol "BOILER-02C, ThisDisplay.Status02C
                      Update_Symbol "BOILER-03C, ThisDisplay.Status03C
                      Update_Symbol "BOILER-04C, ThisDisplay.Status04C
                  End Sub
                  
                  
                  Private Sub Update_Symbol(TagName As String, Sym As Symbol)
                      If server Is Nothing Then
                          Set server = PISDK.Servers.DefaultServer
                      End If
                    
                      Set TagVal = server.PIPoints(TagName).data.Snapshot
                      If TagVal >= 30 Then
                          Sym.LineColor = pbGreen
                          Sym.Contents = Format("Operating")
                      Else
                          Sym.Contents = Format("Failure")
                          Sym.LineColor = pbRed
                      End If
                  End Sub
                  
                  Private Sub Display_Open()
                      ThisDisplay.Width = 820
                      ThisDisplay.Height = 620
                      ThisDisplay.Zoom = 100
                      ThisDisplay.Maximize
                      data.Contents = FormatDateTime(Now)
                      Set server = PISDK.Servers.DefaultServer
                  End Sub
                  

                   

                   

                  Gabriel