Array Class
From SysCAD Documentation
Contents |
Description
The ARRAY class, provides member functions, to create a dynamic array and manipulate its elements. It also allows one to read in an array from a file. The array is zero indexed, ie. the index starts at zero. If the index is out of range (0 <= index < length) then a " PGM class execution error " will occur and the ARRAY operation will be ignored. Note: the initial length of the array is zero.
Data Members
None
Member Functions
Set Array Length
- SetLen (length)
- Parameters
- length : the required length of the array, is of data type LONG.
- Return Value:
- Zero
- Description:
- The length of the array is set to the size of length.
Get Array Length
- Long GetLen( )
- Return Value:
- The length of the array, which is of data type LONG
- Description:
- This returns the current length of the array.
Initialise Array
- SetAll (value)
- Parameters
- value : the required initialising value. This is of data type DOUBLE.
- Return Value:
- Zero
- Description:
- This sets all the elements of the array to the specified value.
Set Value to Array element
- SetAt (index,value)
- Parameters
- index : the index of the required entry in the array (Note: index starts at zero). This is of data type, LONG.
- value : the value to which the specified element, in the array, will be set. This is of data type, DOUBLE.
- Return Value:
- Zero
- Description:
- This sets the element of the array, which corresponds to the given index to the specified value.
Get Array Element value
- double GetAt ( index )
- Parameters
- index : the index of the required entry in the array (Note: index starts at zero). This is of data type LONG.
- Return Value:
- The value of the specified element in the array. This is of data type DOUBLE.
- Description:
- This retrieves the value of the element of the array, which corresponds to the given index.
Bit Load (filename)
- Parameters
- fileName : either the actual filename and path in quotations or a STR variable, which refers to the file.
- Return Value:
- True if the file was read or False if the file was not read.
- Description:
- This creates a new array from a file. The first element on each line, of the specified file, is read in as an element of the array, until either an empty line or end-of-file character is reached.
- Note: if any elements exist in the array, prior to calling Load, these elements will be overridden.
Bit Save (filename)
- Parameters
- fileName : either the actual filename and path in quotations or a STR variable, which refers to the file.
- Return Value:
- True if the file was saved or False if the file was not saved. This could fail for any file access reason, for example: invalid folder, invalid filename, file access error, file already open in another aplication, etc.
- Description:
- This saves the array data to a comma separated text file. If the specified file exists it is overwritten.
Bit CopyToClipboard ()
- Return Value:
- True.
- Description:
- This saves the array data to the clipboard.
IncAt(Index, value)
- Parameters
- index : the index of the required entry in the array (Note: index starts at zero). This is of data type LONG.
- value : the value to which the specified element, in the array, will be increased. This is of data type DOUBLE.
- Return Value:
- Zero
- Description:
- This sets the element of the array with increased value, eg "DataArray.IncAt(3, Qty)" is equivalent to "temp = DataArray.GetAt(3) DataArray.SetAt(3, temp + Qty)"
DecAt(Index, value)
- Parameters
- index : the index of the required entry in the array (Note: index starts at zero). This is of data type LONG.
- value : the value to which the specified element, in the array, will be decreased. This is of data type DOUBLE.
- Return Value:
- Zero
- Description:
- This sets the element of the array with decreased value, eg "DataArray.IncAt(3, Qty)" is equivalent to "temp = DataArray.GetAt(3) DataArray.SetAt(3, temp - Qty)"
Watch
To make the array variables visible in the access window the Watch command can be used. Individual elements in the array can be made visible (eg "Watch A[2]" or "Watch A@[2]"). A range of array elements can be made visible (eg "Watch A[All,5]" which would show the first 5 elements of the array). If these commands are used without the "@" symbol, then the array elements will be input fields that the user can change on the access window of the PGM. If the "@" symbol is added, then the array elements will be read only variables.
Example
STR FileName
DOUBLE d, e
Bit OK@
ARRAY a, b, c ;declares array instances
if (OnInitialise)
FileName = "c:\SysCAD\array.csv"
OK = b.Load(FileName)
OK = c.Load("c:\Data\data.txt")
a.SetLen(5) ;sets the array length
endif
d = a.GetLen() ;gets the array length
a.SetAll(2.2/2) ;sets all elements
a.SetAt(d-1, 3.3) ;sets last element
a.IncAt(0, 7.0) ;increments the first element
e = a.GetAt(0) ;gets first element
