Promotic

Object PmArray (Array of values)

Description:
Object represents an array of values. This object is used in scripts written in the JavaScript language.
Properties and methods:
Array1()Creates and fills 1-dimensional array with values
Create()Creates a 1- or 2-dimensional array
Filter()Allows filtering of 1-dimensional array
GetDim()The array dimension
GetItem()Returns the array item
GetSize()Returns the array size in defined dimension
GetSubArray()Creates 1-dimensional array of values from selected data items of the 2-dimensional array
Insert()Adds one or multiple items into the array
Remove()Removes one or multiple items from the array
SetItem()Sets the value in the array item
SetSubArray()Assignment of the 1-dimensional array of values to the data items of the 2-dimensional array
LoadFromVbArray()Fills in PmArray by copying from the VBScript array
SaveToVbArray()Returns a copy of PmArray as VBScript array
Sort()Array sorting
Note:
- The object can be created by the Pm.CreatePmArray method.
- This object is functional also in Web panels.


In JavaScript panels of the PROMOTIC application it is not possible to use the standard arrays of the VBScript and JavaScript languages (see Language data types). In these panels, all properties and methods use the PmArray - see How to use array of values in the PROMOTIC system.
Comparison of objects used for data storage:
The following object types can be used for holding values (of any data type). Each of these objects has certain advantages and disadvantages and the choice depends on the desired usage.
PmArray: This object contains values that are accessible by index into the array - it is possible to read any value at any time in this object. Reading and writing values is very fast, but adding is slow.
This object is functional only for JavaScript language. For the VBScript language the array is represented by Array data type.
PmMap: This object contains values that are addressed by name (text identifier). Value names represent object properties. The advanatege is the "clarity" of usage in the script code. The disadvantage is the inability to access the values in cycle by index.
PmBuffer: This object contains binary values in the data block. For reading/writing of individual value it is necessary to know its position (offset) in the data block and also the data type (size).
Example1:
Creates and fills 1-dimensional array:
JavaScriptSelect and copy to clipboard

var arr = Pm.CreatePmArray(1, 4);
arr.SetItem(10, 0);
arr.SetItem(20, 1);
arr.SetItem(30, 2);
arr.SetItem(10, 3);
Example2:
Creates and fills 2-dimensional array:
JavaScriptSelect and copy to clipboard

var arr = Pm.CreatePmArray(2, 2, 3);
arr.SetItem(11, 0, 0);
arr.SetItem(12, 1, 0);
arr.SetItem(21, 0, 1);
arr.SetItem(22, 1, 1);
arr.SetItem(31, 0, 2);
arr.SetItem(32, 1, 2);
Example3:
Read the values of the 2-dimensional array:
JavaScriptSelect and copy to clipboard

var arr = pMe.PmPanel.Methods().GetDataArray();
var nCol = arr.GetSize(1);   // See (Col,Row) - 2-dimensional array meaning an array of rows
var nRow = arr.GetSize(2);
for (iCol = 0; iCol < nCol; iCol++)
{
for (iRow = 0; iRow < nRow; iRow++)
{
var val = arr.GetItem(iCol, iRow);
}
}

History:
Pm9.00.25: New methods Insert and Remove for reading/writing row/column in the array.
Pm9.00.04: New methods Insert and Remove for adding and removing items in the array.
Pm8.02.00: Created
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.