This function can only be used with Array and Associative Array variables.

Versions 16 and later

This function is now available for Java applications.

This function is now available for PHP sites.

This function is now available for Android applications.

New in version 16

This function is now available for Java applications.

This function is now available for PHP sites.

This function is now available for Android applications.

This function is now available for Java applications.

This function is now available for PHP sites.

This function is now available for Android applications.

Versions 17 and later

This function is now available for iPhone/iPad applications.

New in version 17

This function is now available for iPhone/iPad applications.

This function is now available for iPhone/iPad applications.

Versions 18 and later

This function is now available in Android Widget mode.

This function is now available in Windows Store apps mode.

New in version 18

This function is now available in Android Widget mode.

This function is now available in Windows Store apps mode.

This function is now available in Android Widget mode.

This function is now available in Windows Store apps mode.

Versions 21 and later

This function is now available in Apple Watch mode.

This function is now available in browser code.

This function is now available in Universal Windows 10 App mode.

This function is now available for List variables.

New in version 21

This function is now available in Apple Watch mode.

This function is now available in browser code.

This function is now available in Universal Windows 10 App mode.

This function is now available for List variables.

This function is now available in Apple Watch mode.

This function is now available in browser code.

This function is now available in Universal Windows 10 App mode.

This function is now available for List variables.

Example

MyArray is array of 2 strings Insert(MyArray, 1, "WINDEV") Insert(MyArray, 2, "WEBDEV") Insert(MyArray, 3, "WINDEV and WEBDEV") // Display the content of 3rd element Trace(MyArray[3]) // Displays "WINDEV and WEBDEV"

MyArray is array of 2 strings MyArray[1] = "WINDEV" MyArray[2] = "WEBDEV" Insert(MyArray, 3, "WINDEV and WEBDEV") // Display the content of 3rd element Trace(MyArray[3]) // Displays "WINDEV and WEBDEV"

// Associative array Last Name - First Name aaLastNameFirstName is associative array of strings Insert(aaLastNameFirstName, "Smith", "Tommy") Insert(aaLastNameFirstName, "Montgomery", "Julia")

Syntax

Inserting an element into an array or into an advanced array property Hide the details

Name of Array variable to use. This array must be a one-dimensional array.

<Insertion subscript>: Integer

Subscript where the element will be inserted into the array. From this subscript, all elements will be moved by 1 element. If <Insertion subscript> is equal to the number of elements in the array +1, the element is added at the end of array (equivalent to ArrayAdd or Add). A WLanguage error occurs if <Insertion subscript> is greater than the number of elements in the array +1.

<Element value>: Any type, optional

Element that will be inserted into the array at the specified position. If this parameter is not specified, the array is enlarged with the default value of the type of the other array elements.

Name of Array variable to use. This array must be a one-dimensional array.

<Element key>: Type of key in the associative array

Value of key for which the element will be inserted. In an associative array without duplicate, a WLanguage error occurs if the element already exists.

<Element value>: Any type

Element that will be inserted into the specified array.

Insert(<WLanguage array> , <Insertion subscript> [, <WLanguage array to insert>])

<WLanguage array>: Array

Name of Array variable to use. This array must be a one-dimensional array.

<Insertion subscript>: Integer

Subscript where the element will be inserted into the array. From this subscript, all elements will be moved by 1 element. If <Insertion subscript> is equal to the number of elements in the array +1, the element is added at the end of the array (equivalent to ArrayAdd). A WLanguage error occurs if <Insertion subscript> is greater than the number of elements in the array +1.

<WLanguage array to insert>: Optional array

Array that will be inserted into <Array name>. This insertion will be performed at the specified insertion subscript.

Subscript where the element will be inserted into the list. The following constants can be used:

FirstElement

The element is inserted at the beginning of list.

LastElement

The element is inserted at the end of list.

BeforeCurrentElement

The element is inserted before the current element. This constant is available when browsing the list elements only. Caution: The element will be browsed by the next iteration if the loop is a descending loop.

AfterCurrentElement

The element is inserted after the current element. This constant is available when browsing the list elements only. Caution: The element will be browsed by the next iteration if the loop is an ascending loop.

<Element value>: Any type

Element that will be inserted into the list at the specified position.

Insert(<WLanguage list> , <Insertion subscript> , <WLanguage list to insert>)

<WLanguage list>: List

Name of List variable to use.

<Insertion subscript>: Integer constant

Subscript where the list will be inserted into the list. The following constants can be used:

FirstElement

The list is inserted at the beginning of <WLanguage list>.

LastElement

The list is inserted at the end of <WLanguage list>.

BeforeCurrentElement

The list is inserted before the current element. This constant is available when browsing the list elements only.

AfterCurrentElement

The list is inserted after the current element. This constant is available when browsing the list elements only.

<WLanguage list to insert>: List

List that will be inserted at the specified insertion subscript.

Remarks

Inserting an element into an array

When Insert is called:

the array is automatically enlarged to receive the new element.

the element is converted (if necessary) into the type of the other array elements.

When declaring an array of N elements, this array contains N empty elements. For example, the array declared below contains 3 empty strings.

MyArray is array of 3 strings

When inserting an element (Insert), this element is automatically inserted among the elements already found in the array.

In our example, the array will contain 4 elements once the insertion is performed.

Inserting an element into an advanced array property

When Insert is called:

the advanced variable must be created.

the advanced type must have an enumerator of modifiable collection type.

the advanced type is automatically enlarged to receive the new elements.

the element is initialized with the value passed in parameter. If no value is passed in parameter, the element is initialized with the default value of the type of the array elements.

Inserting an element into a list

When Insert is called:

the list is automatically enlarged to receive the new element.

the element is converted (if necessary) into the type of the other list elements.

This feature is not available.

Inserting an array

When Insert is called:

the array is automatically resized to receive the new elements. The elements of <WLanguage array to insert> are added at the position specified in <Array name>.

the two arrays must have the same type.

the arrays must have the same dimension.

the values of array dimensions (except for the first one) must be identical.

Inserting a list

When Insert is called:

the list is automatically enlarged to receive the new elements. The elements of <WLanguage list to insert> are added at the specified position.

the two lists must have the same type.

This feature is not available.

Use conditions

This function can be used with the structures. In this case, you must:

Declare a variable (same type as the structure).

Initialize each member.

Pass the structure variable in parameter to Insert.

This function cannot be used on:

non-created arrays,

fixed arrays.

Miscellaneous

To add an element at the end of a one-dimensional array, use ArrayAdd or Add.

To add an element into a sorted array (while respecting the sort), use ArrayAddSorted.