Inserting an element into an array Adding an element to an advanced array property Inserting an element into a list Inserting a table Inserting a list Use conditions Miscellaneous
ArrayInsert (Function)
In french: TableauInsère
Inserts an element at a given position:
into a one-dimensional array. into an associative array. into an advanced array property (array of gglCalendar events, etc.). in a WLanguage list. This function can also be used to concatenate two arrays or two lists.
Remarks :
This function is equivalent to Insert . This function can only be used with Array and Associative array variables.
MonTableau is array of 2 strings
ArrayInsert ( MonTableau , 1 , "WINDEV" )
ArrayInsert ( MonTableau , 2 , "WEBDEV" )
ArrayInsert ( MonTableau , 3 , "WINDEV et WEBDEV" )
Trace ( MonTableau [ 3 ] )
MonTableau is array of 2 strings
MonTableau [ 1 ] = "WINDEV"
MonTableau [ 2 ] = "WEBDEV"
ArrayInsert ( MonTableau , 3 , "WINDEV et WEBDEV" )
Trace ( MonTableau [ 3 ] )
taNomPrenom is associative array of strings
ArrayInsert ( taNomPrenom , "Moulin" , "Françoise" )
ArrayInsert ( taNomPrenom , "Montgomery" , "Julie" )
Syntax
Inserting an element into an array or into an advanced array property Hide the details
ArrayInsert(<WLanguage array> , <Insertion index> [, <Element value>])
<WLanguage array>: Array
Name of the Array variable to use. This array must be a one-dimensional array. <Insertion index>: Integer
Index where the element will be inserted into the array. From this index, all elements will be moved by 1 element. If <Insertion index> 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 index> is greater than the number of elements in the array +1. <Element value>: Any type, optional
Element that will be inserted into the specified array, at the given position. If this parameter is not specified, the array is enlarged with the default value of the type of the other array elements.
Inserting an element into an associative array Hide the details
ArrayInsert(<WLanguage array> , <Element key> , <Element value>)
<WLanguage array>: Array
Name of the 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 must be added to the specified array.
Inserting an array into an array Hide the details
ArrayInsert(<WLanguage array> , <Insertion index> [, <Array to insert>])
<WLanguage array>: Array
Name of the Array variable to use. This array must be a one-dimensional array. <Insertion index>: Integer
Index where the element will be inserted into the array. From this index, all elements will be moved by 1 element. If <Insertion index> 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 index> is greater than the number of elements in the array +1. <Array to insert>: Optional array
Name of the Array variable to insert at the insertion index specified in <WLanguage array>.
Inserting an element into a list Hide the details
ArrayInsert(<WLanguage list> , <Insertion index> , <Element value>)
<WLanguage list>: List
Name of List variable to use. <Insertion index>: Integer constant
Index where the element will be inserted into the list. The following constants can be used:AfterCurrentElement The element is inserted after the current element. This constant is only available to iterate over the elements of the list.Warning The element will be traversed by the next iteration if the loop is ascending. BeforeCurrentElement The element is inserted before the current element. This constant is only available to iterate over the elements of the list.Attention : The element will be traversed by the next iteration if the loop is descending. FirstElement The element is inserted at the beginning of list. LastElement The element is inserted at the end of list.
<Element value>: Any type
Element that will be inserted into the list at the specified position.
Inserting a list into a list Hide the details
ArrayInsert(<WLanguage list> , <Insertion index> , <List to be inserted>)
<WLanguage list>: List
Name of List variable to use. <Insertion index>: Integer constant
Index where the list will be inserted into the list. The following constants can be used:AfterCurrentElement The list is inserted after the current element. This constant is only available to iterate over the elements of the list. BeforeCurrentElement The list is inserted before the current element. This constant is only available to iterate over the elements of the list. FirstElement The list is inserted at the beginning of <List name>. LastElement The list is inserted at the end of <List name>.
<List to be inserted>: List
Name of the list that will be inserted at the specified insertion index. Remarks
Inserting an element into an array
When ArrayInsert 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.
MonTableau is array of 3 strings
Elements inserted using
ArrayInsert are automatically inserted among the existing elements in the array.
In our example, the array will contain 4 elements once the insertion is performed.
Adding an element to an advanced array property
When ArrayInsert 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 new elements. the element is initialized with the value passed as parameter. If no value is passed as parameter, the element is initialized with the default value of the type of the array elements. Inserting an element into a list
When ArrayInsert 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. Inserting a table
When ArrayInsert is called:
the array is automatically resized to include the new elements. The elements of <Name of 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 ArrayInsert is called:
the list is automatically enlarged to receive the new elements. The elements of <Name of list to insert> are added at the specified position. both lists must be of the same type. 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 as parameter to ArrayInsert . 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 .
This page is also available for…