InsertInArray

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

Purpose

Returns an expanded copy of the specified array that includes one new element inserted at the specified index.

Return Type

Array

Syntax

InsertInArray( {ArrayId}, {index}, {value} )

Where:

What it Does

Returns an expanded copy of the specified array that includes one new element inserted at the specified index. The returned array is an expanded copy of {ArrayId} containing one more element with the specified {value} inserted at the specified {index}, such that the corresponding index of all remaining elements from {index} in the source {ArrayId} is shifted +1.

Use AppendArray to append one or more elements from on array to another array.

Use RemoveFromArray to remove elements from an array.

Example

This sample code will return an array with the values 1,9,2,3,4.

Integer[] myArray

 

Move 1 to myArray[0]

Move 2 to myArray[1]

Move 3 to myArray[2]

Move 4 to myArray[3]

 

Move (InsertInArray(myArray, 1, 9)) to myArray

Examples

This sample code will return an array of 4 tFriend structs where new friend Amanda Edwards is inserted before Frank Jones as the second array element (at index 1).

Struct tFriend

    String First

    String Last

End_Struct

 

Procedure Test

    tFriend[] myFriends

 

    Move "Joe" to myFriends[0].First

    Move "Cool" to myFriends[0].Last

    Move "Frank" to myFriends[1].First

    Move "Jones" to myFriends[1].Last

    Move "Susie" to myFriends[2].First

    Move "Smith" to myFriends[2].Last

 

    tFriend newFriend

    Move "Amanda" to newFriend.First

    Move "Edwards" to newFriend.Last

 

    Move (InsertInArray(myFriends, 1, newFriend)) to myFriends

End_Procedure

This sample is identical to the prior sample, with the exception that -1 is passed as the index, thus appending the new element (Amanda Edwards) to the end of the array.

Struct tFriend

    String First

    String Last

End_Struct

 

Procedure Test

    tFriend[] myFriends

 

    Move "Joe" to myFriends[0].First

    Move "Cool" to myFriends[0].Last

    Move "Frank" to myFriends[1].First

    Move "Jones" to myFriends[1].Last

    Move "Susie" to myFriends[2].First

    Move "Smith" to myFriends[2].Last

 

    tFriend newFriend

    Move "Amanda" to newFriend.First

    Move "Edwards" to newFriend.Last

 

    Move (InsertInArray(myFriends, -1, newFriend)) to myFriends

End_Procedure