Skip to content

AppendArray

See Also: SizeOfArray, ResizeArray, Array Functions, Array Variable Assignments, Working with Arrays

Purpose

Returns an array consisting of one array appended to another array.

Return Type

Array

Syntax

AppendArray({Array1Id}, {Array2Id})
AppendArray({Array1Id}, {Array2Id} [, {indexFirst}, {indexLast}])

Parameters

  • {Array1Id}: The id of the array to which to append a second array. Must be a dynamic array.
  • {Array2Id}: The id of the array to append to the first array. Must be a dynamic array.
  • {indexFirst}: The starting dimension index of {Array2Id} to append to the first array.
  • {indexLast}: The ending dimension index of {Array2Id} to append to the first array.

What it Does

Returns an array consisting of one array appended to another array. If {indexFirst} and {indexLast} are passed, only that sub-range of the second array is appended to the first array. The arrays must be of the same type. Both source arrays and the destination array must be dynamic.

This can be particularly useful when working with UChar arrays.

Use InsertInArray to insert or append individual array elements to an array.

Use RemoveFromArray to remove elements from an array.

Tip: AppendArray Alternative

You can append values to the end of a dynamic array using Move and passing [-1] as the array indexer as a substitute for using AppendArray.

Procedure Example
    String[] Sentence
    Move "The" to Sentence[-1]
    Move "quick" to Sentence[-1]
    Move "brown" to Sentence[-1]
    Move "fox" to Sentence[-1]
    Move "jumps" to Sentence[-1]
    Move "..." to Sentence[-1]
End_Procedure

Example 1

The following example appends the names in source arrays sGroupAmericaNames and sGroupEuropeNames and places them in destination array sCombinedGroupNames.

The result would be: John, Marcia, Americo, Dennis, Chip, Vincent, Nick, Janine, Harm, Eddie.

Procedure OnClick
    String[] sGroupAmericaNames sGroupEuropeNames sCombinedGroupNames
    Move "John" to sGroupAmericaNames[0]
    Move "Marcia" to sGroupAmericaNames[1]
    Move "Americo" to sGroupAmericaNames[2]
    Move "Dennis" to sGroupAmericaNames[3]
    Move "Chip" to sGroupAmericaNames[4]
    Move "Vincent" to sGroupEuropeNames[0]
    Move "Nick" to sGroupEuropeNames[1]
    Move "Janine" to sGroupEuropeNames[2]
    Move "Harm" to sGroupEuropeNames[3]
    Move "Eddie" to sGroupEuropeNames[4]
    Move (AppendArray(sGroupAmericaNames, sGroupEuropeNames)) to sCombinedGroupNames
End_Procedure

The names in the destination array are added in the order they are received from the source arrays. You could call SortArray to sort the destination array:

Move (SortArray(sCombinedGroupNames)) to sCombinedGroupNames

The result would be: Americo, Chip, Dennis, Eddie, Harm, Janine, John, Marcia, Nick, Vincent.

Example 2

The following example appends the names in source array sGroupEuropeNames from array indexer 3 to 4 and to all names in source arrays sGroupAmericaNames, placing them in destination array sCombinedGroupNames.

The result would be: John, Marcia, Americo, Dennis, Chip, Harm, Eddie.

Procedure OnClick
    String[] sGroupAmericaNames sGroupEuropeNames sCombinedGroupNames
    Move "John" to sGroupAmericaNames[0]
    Move "Marcia" to sGroupAmericaNames[1]
    Move "Americo" to sGroupAmericaNames[2]
    Move "Dennis" to sGroupAmericaNames[3]
    Move "Chip" to sGroupAmericaNames[4]
    Move "Vincent" to sGroupEuropeNames[0]
    Move "Nick" to sGroupEuropeNames[1]
    Move "Janine" to sGroupEuropeNames[2]
    Move "Harm" to sGroupEuropeNames[3]
    Move "Eddie" to sGroupEuropeNames[4]
    Move (AppendArray(sGroupAmericaNames, sGroupEuropeNames, 3, 4)) to sCombinedGroupNames
End_Procedure