AnsweredAssumed Answered

PI Processbook: Multistate for integer tags issue

Question asked by cyberterrorist on Oct 13, 2020

I want to use integer tag in multistate in Processbook. States definition based on tag intervals is:

0,0 - state1

1,1 - state2

2, 100 - state3

If I do this manually, in first step I define first state by defining upper limit =0 (low limit is default). When I want to define state2 by defining upper limit 1, Processbook allows to input number only >=2. I found workaround for this. For state1 I define firstly upper limit as 1 and then I change it to 0. State 1 Low limit is then somehow recalculated to -1 (despite tag zero is 0) and then state1 can be set with upper limit 1 (and any number of such states including only one number).

I want to implement this programatically in VBA however with no success for many alternatives. Basic code is bellow. I think issue is, that in definestate I have to define both limits and thus low limit for state1 isn't recalculated to -1. If I set -1 to interval in code or I imitate manual workaround mentioned above, Processbook ignores it. Do you have any idea how to implement such multistate programatically in VBA? I don't want to change tag.


Public Sub intmult()

  Dim objMultiState As MultiState
  Dim objMSState As MSState

  With ThisDisplay.Symbols("rect1")
    Set objMultiState = .CreateMultiState("some integer tag")
    objMultiState.StateCount = 3
    objMultiState.DefineState 3, -1, 100
    Set objMSState = objMultiState.GetState(1)
    objMSState.DefineState 0, 0, RGB(200, 0, 0)
    Set objMSState = objMultiState.GetState(2)
    objMSState.DefineState 1, 1, RGB(0, 230, 0)
    Set objMSState = objMultiState.GetState(3)
    objMSState.DefineState 2, 100, RGB(0, 0, 200)
    objMultiState.ColorBadData = RGB(255, 255, 255)
    .SetMultiState objMultiState
  End With

End Sub