5 Replies Latest reply on Feb 20, 2015 4:33 PM by pthivierge

    Bad Data Pi Processbook

    paulpwr

      Hi,

       

      I have a display with over 500 tags, around 200 of these are multi state. I don't want the word bad to appear for any of the 500 tags, I just want them to be set to clear colour when they are bad. This is easy with the multi state values but is there an easy way to apply this to the other 300 tags without converting them to multi state values?

        • Re: Bad Data Pi Processbook
          Asle Frantzen

          Hi Paul

           

          Try adding this VBA function to the display you want to do this for:

           

          Private Sub Display_Open()
              Dim mySymbol As Long
              Dim myValueSymbol As Value
              Dim theValue As Variant
              Dim vrDate As Variant
              Dim vrStatus As Variant
              For mySymbol = 1 To ThisDisplay.Symbols.Count Step 1
                  
                  Set myValueSymbol = ThisDisplay.Symbols(mySymbol)
                  
                  If (myValueSymbol.Type = pbSymbolValue) Then
                      theValue = myValueSymbol.GetValue(vrDate, vrStatus)
                      
                      On Error Resume Next
                      
                      If (vrStatus <> 0) Then
                          myValueSymbol.LineColor = vbRed
                      Else
                          myValueSymbol.LineColor = vbWhite
                      End If
                  End If
              Next mySymbol
          End Sub
          

           

          I don't know how it'll perform, but it iterates through all symbols, checks whether it's a value symbol, and then marks all values with bad value in a red color.

            • Re: Bad Data Pi Processbook
              dng

              Hi Paul,

               

              Asle's example works (by the way, if you want a transparent color, set the LineColor to -1). One thing you want to consider is how often do you want to check the tags for bad status. You can certainly check it for each DataUpdate event, but this means the VBA code is going to be executed pretty often.

               

              Another idea is to let multi-state takes care of that for you. You can use some VBA code to add multi-state to all the value symbols in bulk (e.g. How to change multi-state in batch?)

                • Re: Bad Data Pi Processbook
                  paulpwr

                  Thanks for the replies. The issue is that they are Live values and constantly change, also all the Multi values are all different so I am not sure changing them in bulk would be the best idea. Its only if the value returned says  "bad" do I want it to clear

                    • Re: Bad Data Pi Processbook
                      dng

                      I can't find any out-of-the-box way to set the bad values to a transparent color. It looks like you either have to use multi-state or VBA to achieve your goal. My initial idea was to set the multi-state to the same tag as the value symbol, then set all states to have the same color, e.g.

                       

                      Sub Test()
                          Dim sym As Symbol
                          Dim myMultiState As MultiState
                          Dim myState As MSState
                         
                          For Each sym In ThisDisplay.Symbols
                              If ((sym.Type = pbSymbolValue) And (Not sym.IsMultiState)) Then
                                  Set myMultiState = sym.CreateMultiState(sym.GetTagName(1))
                                  myMultiState.StateCount = 2
                                  myMultiState.ColorBadData = -1
                                  Set myState = myMultiState.GetState(1)
                                  myState.Color = RGB(255, 255, 255)
                                  myState.Blink = False
                                  Set myState = myMultiState.GetState(2)
                                  myState.Color = RGB(255, 255, 255)
                                  myState.Blink = False
                              End If
                          Next
                      End Sub
                      

                       

                      This code will only be executed once.

                       

                      Alternatively, Asle's solution works perfectly fine. Just set to run at Display_DataUpdate().

                • Re: Bad Data Pi Processbook
                  pthivierge

                  Hi Paul.

                   

                  That sounds a bit simple:

                  What about adding a shape that has same color as the background over it that is visible only when the tag value is bad?