11 Replies Latest reply on Feb 25, 2016 6:44 AM by Eugene Lee

    VB Code for processbook

    vdhar1992

      I want a write a vb code in process book. The condition is  if Tag value is greater then 0 but hasn't change from last 15 mins the background colour must be orange.

        • Re: VB Code for processbook
          Karl.Hodgkiss

          Instead of VB you could run a multistate based on a PE or Analysis that says something like:

          IF TAGVAL('TAG1') > 0 AND TAGAVG('TAG1', '*-15m', '*') = 'TAG1' THEN 0 ELSE 1

          .

          3 of 3 people found this helpful
            • Re: VB Code for processbook
              vdhar1992

              I have a process book display ready with the VB code. I just need to include this one condition. It will be very much helpful if I can get this in VB

                • Re: VB Code for processbook
                  gregor

                  Hello Vaishali,

                   

                  The solution Karl has suggested appears reasonable. A solution that works out of the box should always be preferred upon a programmatic approach.

                   

                  When you say, you have a display ready with the VB code but need to include this one, what exactly does that mean? E.g. do you need to know how to set the displays background color or what's the missing piece?

                    • Re: VB Code for processbook
                      vdhar1992

                      Hello Gregor,

                       

                      I have a display prepared with all other conditions programmed in VB only. I have to include this one more condition where the if the tag value is greater than zero but haven't changed in last 15 minutes so the colour of the background where the tag is mentioned in the display should turn orange. This is similar to the other condition in my display where if the value of the tag is less than zero then the colour should change to red.

                        • Re: VB Code for processbook
                          Eugene Lee

                          Hi Vaishali,

                           

                          Here you go!

                           

                          Dim calc As IPICalculation
                          Set calc = Servers.DefaultServer
                          If calc.Calculate("*", "*", "IF TAGVAL('tag1') > 0 AND TAGAVG('tag1', '*-15m', '*') = 'tag1' THEN 1 ELSE 0", SampleTypeConstants.stRecordedValues, Null)(1).Value Then
                          ThisDisplay.BackgroundColor = RGB(255, 165, 0)
                          End If
                          
                          2 of 2 people found this helpful
                            • Re: VB Code for processbook
                              vdhar1992

                              Thanks Eugene...This is working perfectly fine

                                • Re: VB Code for processbook
                                  vdhar1992

                                  Hi Eugene,

                                   

                                  By this approach I have noticed one issue. If the all the values are not equal in the last 15 minutes and have a very small deviations like less than 0.5 than also the code is treating as the value equal to the current value. How can this be corrected? I don't intend have any deviations in the result.

                                    • Re: VB Code for processbook
                                      Eugene Lee

                                      Hi Vaishali,

                                       

                                      You might want to try adding some conditions to make sure the MIN and MAX doesn't get out of the range that you want during that time range. The reason I say this is because for example,

                                       

                                      The average of 2+4 can be 3. But we only want the condition to trigger if and only if the average of 3+3 is 3. Therefore, we might need to add MAX during that time range should be equal to 3 and also MIN of that time range should be equal to 3.

                                        • Re: VB Code for processbook
                                          vdhar1992

                                          Thanks Eugene that was really helpful. i would like to add one more condition to this code. I would like to add a reset button in the display. If there is any bad value in those 15 mins, the colour should change to red and hold it until reset button is pressed irrespective of the fact that good values are now received in the tag.

                                            • Re: VB Code for processbook
                                              Eugene Lee

                                              Hi Vaishali,

                                               

                                              You can add another condition to check for a boolean flag (needs to be a GLOBAL variable) value to be True. In this case then, you should use the logic 'Or' when joining this condition with the other 3 conditions like such if boolean flag has a variable name of flag1:

                                               

                                              If (condtion1 And condition2 And condition3) Or flag1 Then

                                              'change display colour

                                              flag1=false

                                              End If

                                               

                                              For your reset button, you can it to execute a macro such as below when clicked:

                                               

                                              flag1=True

                                              'change display colour back to original colour

                                • Re: VB Code for processbook
                                  dbard

                                  Using VBA will limit what you can do with that display moving forward.  Using AF analytics will "future proof" the display. 

                                   

                                  Just a suggestion.

                                  3 of 3 people found this helpful