Array Variables

Array variables are one of types of variables that can be defined in the Movicon Real Time DB.  The Array variables support the following element types:

 

 

The following array types cannot be created:"Bit", "String", "Structure" Arrays or"Array" Arrays.

 

"The Array type variables can be sized with a maximum of 4096 elements.  The address of the first element should be '0' therefore when you define an Array with 10 elements they should be addressed from "0" a "9".

In order to size an Array variable you will need to set the Internal Address in the variable's Advance properties by defining the number of array elements using the  "x(x)" syntax. For example, when entering "0(5)" this would define an array with 5 elements. As the 'Area' property is set at the default 'Not Shared' value, the internal address will not be recognized:  the variable will only be identified through its name.

The Array variables can be defined with a maximum no of 4096 elements.

 

They can be used in different project controls and resources such as screen objects, Alarms, DataLogger-Recipes, IL Logic etc.. The syntax used for accessing Array elements are:"

 

 

Where:

"#" = is a numeric value which represents the number of elements to be pointed to  (i.e. Array[1])

"IndexVar" = is the name of a numeric variable that contains the number of elements to pointed to.  It allows you to dynamically change the number of elements to be accessed (i.e. Array[VAR00001])

"BitNum" = is a numeric value which represents the number of the Array's element's bits to  point to (i.e.Array[1].0)

 

All the above syntax can be used for accessing in Array elements in read/write and there is no need to enable the variables' "Intellisense" properties.

When opening the "Tag Browser" window for selecting a variable, you will find that the Array variables have a  "+" cross on the left hand side of their name.  When clicking on the Array, it will expand to show a list of its elements which can then be selected singularly.

 

 

Using Array Variables in Basic expressions

Array variables can also be used in the objects' basic expressions for which the following syntax can be  used:

 

Array.e# ("Intellisense" property must be enabled)

[Array.e#] ("Intellisense" property can be enabled or disabled indifferently)

 

Variables CANNOT be used as element indexes and  element bits CANNOT be accessed when using Array variable in basic expressions.

 

Basic expression examples

The VarArray1 is an Array variable type with its "Intellisense" property disabled:

 

[VarArray1.e0] + VAR00001

VAR00001 + ([VarArray1.e0] * VAR00002)

 

The VarArray2 is a array variable type with its  "Intellisense" property enabled:

 

VarArray2.e0 + VAR00001

VAR00001 + (VarArray2.e0 * VAR00002)

 

 

Using Array variables in Basic Script code

The  Array variables can be used within Basic Script Code for which the following syntax can be used:

 

Array.e# ( "Intellisense" property must be  enabled)

[Array.e#] (with or without enabling "Intellisense" property)

GetVariableValue("Array[#]") (with or without enabling "Intellisense")

SetVariableValue("Array[#]", 1) (with or without enabling "Intellisense")

GetVariableValue("Array[" & IndexVar & "]") (with or without enabling "Intellisense")

SetVariableValue("Array[" & IndexVar & "]", 1) (with or without enabling "Intellisense")

 

It is  NOT permitted  to access element bits when Using Array variables in basic expressions.

 

Examples of using Arrays in Script Code:

The VarArray1 is an Array type variable with its  "Intellisense" property disabled:

 

VarValue = GetVariableValue("VarArray1[0]")

SetVariableValue("VarArray1[0]", 1)

 

VarValue = GetVariableValue("VarArray1[" & IndexVar & "]")

SetVariableValue("VarArray1[" & IndexVar & "]", 1)

 

The VarArray2 is an array type variable with its "Intellisense" property enabled:

 

VarArray2.e0  = VarArray2.e0 + 1

 

Events in Variables within Script Code

The element of an Array variable can also be used for managing a "Variable Script Event" for Basic Script and Objects.  When selecting an Array element for managing a "New Event in Variable", the event created in the script will be the one inserted substituting the angled brackets with the underscore character.  For example, when inserting an event in "VarArray1[5]" variable, the event will be inserted with this syntax:

 

Sub OnVarArray1_5_Changed(ByRef value As Variant)

 

 

Using Arrays between Parent-Child projects

The above described syntax can be used in Parent-Child architectures for accessing Array variables from the Parent project to the Child project and vice-versa. In this case you will also have to add the required syntax to all the variables for accessing Parent/Child resources.

Please take into account that when accessing from the Parent project to the Array variables of a Child project or from the Child project to Array variables of the Father project using a variable to define the array element's index to be pointed to, the variable's index will only be searched for within the variable's context in the project.  For example, When accessing a Child project's Array, the index variable must be passed using the name of the variable only (without prefixes) and must defined in the Child project:

 

child1\VarArray1_Child1[ChildIndexVar1]

 

Where ChildIndexVar1 is the Child project.

The same goes when accessing Parent project variables from the Child project.  The syntax uses is:

 

..\VarArray1[ParentIndexVar1]

 

where ParentIndexVar1 is a Parent project variable.

 

Examples of using Array variables between Parent and Child projects

Supposing we have a Parent project and a Child project called  "child1" we could have:

 

child1\VarArrayChild1[0]

child1\VarArrayChild1[0].0

child1\VarArrayChild1.e0

[child1\VarArrayChild1.e0] + VAR00001

child1\VarArrayChild1[ChildIndexVar1]

child1\VarArrayChild1[ChildIndexVar1].0

 

..\VarArrayParent[0]

..\VarArrayParent[0].0

..\VarArrayParent.e0

[..\VarArrayParent.e0] + VAR00001

..\VarArrayParent[ParentIndexVar1]

..\VarArrayParent[ParentIndexVar1].0

 

Where:

 

VarArrayChild1 and ChildIndexVar1 are Child project variables.

VarArrayParent and ParentIndexVar1 are Parent project variables.

 

Importing Array variables from an OPC Server

When importing Array items from an OPC Server, Movicon will create the array variable with the same number of elements in the same type as the OPC Server's.  However, if the OPC item is an array of values not supported by Movicon, for instance: Bit Array, Data Arrays, etc.  The variable will be created as a byte or word Array according to the OPC type with element length equal to zero.

 

Even though Movicon does not support bit arrays, a bit array can be linked to a bit structure which the user can create with any number of elements.

 

Managing Bytes in Use

When an Array variable is exchanged with the field  (Driver, OPC) the bytes-in-use count is only managed for elements that are effectively in use in the  project.

As regards to  Networking, the use of bytes on the Client side is calculated by counting the bytes of each single element exchanged with the Server.  Conversely,  all of the Array variable is put into use in the Server and therefore the byte count is based on the total bytes of all the Array elements.

 

 

 

See Also