CopyArray

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

Purpose

Returns array representing a range of elements from the existing array.

Return Type

Array

Syntax

(CopyArray( {ArrayId}, {indexFirst}, {indexLast} ))

Where:

What it Does

Creates new array from elements within the range of existing array.

 

Example

This sample declares an integer array (integers1) and fills it with the numbers 1 through 100. Next, it copies the first 20 elements of integers1 to array (integers2), then displays all elements of the new array (integers2).

// fires when the button is clicked

Procedure OnClick

    Integer[] integers1 integers2

    Integer i iSize

 

    For i From 0 to 99

        Move (i+1) to integers1[i]

    Loop

 

    Move (CopyArray(integers1, 0, 19)) to integers2

    

    Move (SizeOfArray(integers2)) to iSize

    For i From 0 to (iSize-1)

        showln "integers2[" (string(i)) "] = " (string(integers2[i]))

    Loop

End_Procedure

Example

This sample declares a two-dimensional dynamic array (integers1), containing an undefined number of elements of type integer. It then fills the second dimension of the array 10 times with the numbers 1 through 10, creating a total of 100 elements. Next, the sample copies the first 5 outer elements of integers1 to a dynamic array (integers2), then displays all elements of the new array (integers2).

// fires when the button is clicked

Procedure OnClick

    Integer[][] integers1 integers2

    Integer i j iSize

 

    For i From 0 to 9

        For j From 0 to 9

            Move (j+1) to integers1[i][j]

        Loop

    Loop

 

    Move (CopyArray(integers1, 0, 5)) to integers2

 

    Move (SizeOfArray(integers2)) to iSize

    For i From 0 to (iSize-1)

        For j From 0 to 9

            showln "integers2[" (string(i)) "][" (string(j)) "] = " (string(integers2[i][j]))

        Loop

    Loop

End_Procedure

Notes

Example

This sample declares an integer array (integers1) and fills it with the numbers 1 through 100. Next, it copies the entire array integers1 (including the contents of all elements) to array integers2, then displays all elements of the new array (integers2).

// fires when the button is clicked

Procedure OnClick

    Integer[] integers1 integers2

    Integer i iSize

 

    For i From 0 to 99

        Move (i+1) to integers1[i]

    Loop

 

    // full array copy

    Move integers1 to integers2

    

    Move (SizeOfArray(integers2)) to iSize

    For i From 0 to (iSize-1)

        showln "integers2[" (string(i)) "] = " (string(integers2[i]))

    Loop

End_Procedure