# StrArray Class

Navigation: PGMs -> Classes -> Predefined Classes

## Contents

### Description

The String Array class allows user to Get / Set String values. Please see Array Class for getting/setting numeric values.

The StrArray (String Array) class provides member functions to create a dynamic string array and manipulate its elements.

• The StrArray is zero indexed, i.e. the index of the first element in the StrArray is zero, and NOT 1. Therefore, the final element in a StrArray of length n will have an index = n-1.
• If the index is out of range (length <= index) then a " PGM class execution error " will occur and the StrArray operation will be ignored.

Note: the initial length of the array is zero.

None

### Member Functions

 Call Functionality Return Type Parameters Example SetLen (length) The length of the StrArray is set to the size of length length : the required length of the StrArray, is of data type INTEGER a.SetLen(5) GetLen( ) The function returns the length of the StrArray. Long None x = TagGroup.GetLen() SetAt (index, Text String) This sets the element of the array, which corresponds to the given index to the specified Text String. index : the index of the required entry in the StrArray (Note: index starts at zero). This is of data type, INTEGER. Text String : the value to which the specified element, in the StrArray, will be set. This is of data type, STRING. TagGroup.SetAt(0, "Valid SysCAD Variable Name") GetAt ( index ) This retrieves the value (type real) of the element from the array, which corresponds to the given index. String index : the index of the required entry in the array (Note: index starts at zero). This is of data type INTEGER. Rqd_Tag = TagGroup.GetAt(0) SetAll (Text String) This sets all the elements of the StrArray to the specified Text String. Text String : the required initialising Text String. This is of data type STRING. TagGroup.SetAll("Valid SysCAD Variable Name")

### Watch

To make the StrArray variables visible in the access window the Watch command can be used.

• Individual elements in the array can be made visible - e.g. "Watch TagGroup[2]" or "Watch TagGroup@[2]".
• A range of StrArray elements can be made visible - e.g. "Watch TagGroup[All,5]" which would show the first 5 elements of the StrArray.
• If the "@" symbol is included, then the StrArray elements will be read only fields in the access window.

### Caution

Using a GetAt within a SetAt can sometimes fail.

;For example:
TagGroup.SetAt(i, TagGroup.GetAt(i+1))  ;This can sometimes fail

;The solution is to use a temporary variable to first retrieve the GetAt value and then call SetAt as follows:
STRING   TmpString
TmpString = TagGroup.GetAt(i+1)
TagGroup.SetAt(i, TmpString)


### Example using SysCAD 9.3 Syntax

PageLabel("StrArray")
TextLabel()
STRING     Tag1@, Tag2@, Tag3@, Required_Tag@
LONG       x@
StrARRAY   TagGroup
Watch TagGroup[All,5]

Sub InitialiseSolution()
TagGroup.SetLen(5)             ;sets the StrArray length
EndSub

Tag1 = "P_4.To (C)"
Tag2 = "P_5.To (C)"
Tag3 = "P_6.To (C)"

x = TagGroup.GetLen()
TagGroup.SetAt(0, Tag1)
TagGroup.SetAt(1, Tag2)
TagGroup.SetAt(2, Tag3)
TagGroup.SetAt(4, "P_7.To (C)")
Required_Tag= TagGroup.GetAt(1)