Skip to content

IsSameArray

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

Purpose

Used to determine if two arrays are the same in all but name.

Return Type

Boolean

Syntax

(IsSameArray({Array1Id}, {Array2Id}))

Where:

  • {Array1Id} is the id of the first array to compare.
  • {Array2Id} is the id of the second array to compare.

What it Does

Returns True if the two arrays are the same. They are considered the same if they are of the same type, have the same number of dimensions, the same dimension size, and the same content.

Examples

This example shows that two arrays of the same type are the same after just being instantiated. At this point, the two arrays' types, dimensions, and content (they are both empty) are the same.

Integer[4] iArrayA
Integer[4] iArrayB

If (IsSameArray(iArrayA, iArrayB)) Begin
    Send Info_Box "Both arrays are the Same"
End
Else Begin
    Send Info_Box "Both arrays are NOT the Same"
End

This example shows that two arrays of the same type (meaning they have the same initial type and dimensions) are no longer the same after data was moved to one, but not the other.

Integer[4] iArrayA
Integer[4] iArrayB

Move 5 to iArrayA[0]

If (IsSameArray(iArrayA, iArrayB)) Begin
    Send Info_Box "Both arrays are the Same"
End
Else Begin
    Send Info_Box "Both arrays are NOT the Same"
End

This example shows that two arrays of similar type, containing the same data and dimensions (both integer arrays containing 4 integer elements of identical data), but with one declared as static and the other dynamic, are not considered the same array, since they are of different types (static vs. dynamic).

Procedure OnClick
    Integer[4] iArrayA
    Integer[] iArrayB

    Move 1 to iArrayA[0]
    Move 2 to iArrayA[1]
    Move 3 to iArrayA[2]
    Move 4 to iArrayA[3]

    Move 1 to iArrayB[0]
    Move 2 to iArrayB[1]
    Move 3 to iArrayB[2]
    Move 4 to iArrayB[3]

    If (IsSameArray(iArrayA, iArrayB)) Begin
        Send Info_Box "Both arrays are the Same"
    End
    Else Begin
        Send Info_Box "Both arrays are NOT the Same"
    End
End_Procedure