AnsweredAssumed Answered

Creating an array through VBA code

Question asked by JMARCELO on Aug 31, 2017
Latest reply on Sep 1, 2017 by JMARCELO

Hi guys!

 

I am developing a small and simple display using Processbook, where I need to show part of the informations depending on a violation criteria.

 

Things work this way: I have a column with 8 objects (Value1, Value2, ..., Value8), each one assigned to a specific Tag, that need to change color (Linecolor) based on their values.

 

If the value is next to limit violation (less than 1% from limit), they need to be shown in yellow;

 

If they are out of bounds, they need to be shown in red;

 

If the value is inside the range, linecolor needs to be black.

 

This intends to create a display where only relevant information will appear for the operators I work with.

Using VBA code, I developed a small program that compares the values retrieved in real-time with the pre-defined limits.

The problem is: how can I create an array with the 8 objects in order to make my VBA code work?

 

Here is the code:

 

Private Sub Display_DataUpdate()

Dim Tensoes(7), Linfa(7), Lsupa(7) As Integer

Dim Fecha, Estado As Variant

With ThisDisplay

    Tensoes(0) = Value1.GetValue(Fecha, Estado) 'Gets the actual value of this specific Tag

    Linfa(0) = Value9.GetValue(Fecha, Estado)   'Gets the lower limit  of this specific Tag

    Lsupa(0) = Value10.GetValue(Fecha, Estado)  'Gets the upper limit  of this specific Tag

    If (Tensoes(0) > 1.01 * Linfa(0)) And (Tensoes(0) < 0.99 * Lsupa(0)) Then

        Value1.LineColor = 0 'This is the place where I am having problems! I don't want to refere to Value1 spceficially. I need to refer to ValueX, so that X can range from 1 to 8.

    Else

        If ((Tensoes(0) <= 1.01 * Linfa(0)) And (Tensoes(0) >= Linfa(0))) Or ((Tensoes(0) >= 0.99 * Lsupa(0)) And Tensoes(0) <= Lsupa(0)) Then

            Value1.LineColor = 65535 'This is the place where I am having problems! I don't want to refere to Value1. I need to refer to ValueX, so that X can range from 1 to 8

        Else

            Value1.LineColor = 255 'This is the place where I am having problems! I don't want to refere to Value1. I need to refer to ValueX, so that X can range from 1 to 8

        End If

    End If

End With

End Sub

 

And here is the screen.

 

 

Thanks for the support!

Outcomes