5 Replies Latest reply on Sep 3, 2016 10:55 PM by gregor

    How can I add trace depending on  multi-state symbol's state?

    99anger

      Hello users!

      My processbook have a few multi state symbols(Rectangle1, Rectangle2, Rectangle3......) and a trend symbol

      Each symbol is assigned with analog tag and has 2 states(state1 is red, 2 is green)

      Nothing happens when tag value is normal(state 2, green)

      But If value is abnormal(state 1, red), I would like to add trace value of symbol on trend automatically

      How can I using VBA?

        • Re: How can I add trace depending on  multi-state symbol's state?
          Steve Boyko

          The first step is to enable scripting for each rectangle.

          Then in VBA, create a subroutine to handle the StateChanged event on each rectangle.

          In that subroutine, you will want to either add or remove the trace from the trend depending on the state of the rectangle.

          There is example code in ProcessBook's VBA help file for that. Look for AddTrace() to add a trace.

          That should help you get started!

          1 of 1 people found this helpful
            • Re: How can I add trace depending on  multi-state symbol's state?
              99anger

              Oh Thanks for reply

              I know VBA code for adding trace, but know nothing of handling StateChanged event on multi-state symbol

              I don't have idea how to get state of each reatangle.

              Couldn't you make VBA code sample?

                • Re: How can I add trace depending on  multi-state symbol's state?
                  pmartin

                  Hi Lim,

                   

                  Here's some code that does what you requested.  You will need to change your server name, object names, and what state you are looking for.

                   

                  Private Sub Rectangle1_StateChanged(bCancelDefault As Boolean)
                      Dim tag As String
                      tag = Rectangle1.GetMultiState.GetPtTagName
                     
                      'Check if the current state is 3 (this is for my particular setup, you will need to change it)
                      If Rectangle1.GetMultiState.CurrentState = 2 Then
                          'Check if the tag doesn't already exist on the trend
                          If CheckTrendForTag(tag) = -1 Then
                              Trend1.AddTrace (tag)
                          End If
                      Else
                          Dim i As Integer
                         
                          'Find the index of the tag
                          i = CheckTrendForTag(tag)
                          If i > 0 Then
                              Trend1.RemoveTrace ( i )
                          End If
                      End If
                  End Sub
                  
                  
                  
                  
                  Function CheckTrendForTag(tag As String) As Integer
                      Dim name As String
                      Dim tagName As String
                     
                      'Search through the trend traces to see if your tag name exists there
                      For i = 1 To Trend1.TraceCount
                          tagName = ThisDisplay.Trend1.GetTagName(i)
                          name = "\\servername\" & LCase(tag)
                          If LCase(tagName) = name Then
                              CheckTrendForTag = i
                              Exit Function
                          End If
                      Next
                      CheckTrendForTag = -1
                  End Function
                  
                  1 of 1 people found this helpful