|
|
|
|
|
- Adding an element into a WLanguage array
- Adding an element to an advanced array property
- Adding an element into a list
- Adding an array into an array (concatenation)
- Adding a list into a list (concatenation)
- Adding the content of a structure to an array of structures without using a variable of the structure
- Use conditions
- Miscellaneous
<Array>.Add (Function) In french: <Tableau>.Ajoute Adds an element in last position: - of a one-dimensional WLanguage array.
- of an advanced array property (array of gglCalendar events, array of Word Processing document, etc.).
- of a WLanguage list.
This function can also be used to concatenate two arrays or two lists.
MyArray is array of 2 strings MyArray.Add("WINDEV") MyArray.Add("WEBDEV") MyArray.Add("WINDEV and WEBDEV") // Display the content of 3rd element (the first 2 elements are empty) Trace(MyArray[3]) Â // Displays "WINDEV"
MyArray is array of 2 strings MyArray[1] = "WINDEV" MyArray[2] = "WEBDEV" MyArray.Add("WINDEV and WEBDEV") // Display the content of 3rd element Trace(MyArray[3]) // Displays "WINDEV and WEBDEV"
Syntax
Adding an element to an array, to an advanced array property or to a list Hide the details
<Result> = <WLanguage variable>.Add([<Value>])
<Result>: Integer Index at which the specified element was added. If an error occurs, a fatal error is displayed. <WLanguage variable>: Array or List Name of variable to use. This variable can be:- An Array variable.
- A List variable.
This type of variable is not available.
<Value>: Type of array elements, optional Value that will be added to the array or to the list. This parameter is mandatory for a list.For an array, if this parameter is not specified, the array is enlarged with the default value of the type of the other array elements.
Concatenating arrays or lists Hide the details
<Result> = <WLanguage variable>.Add([<Variable to concatenate>])
<Result>: Integer Index at which the specified element was added. If an error occurs, a fatal error is displayed. <WLanguage variable>: Array or List Name of variable to use. This variable can be:- An Array variable.
- A List variable.
This type of variable is not available.
<Variable to concatenate>: Optional array or list Name of variable that will be added after the existing elements. This variable can be:- An Array variable, to concatenate two arrays. This array must be a one-dimensional array.
- A List variable, to concatenate two lists.
This type of variable is not available.
Remarks Adding an element into a WLanguage array When <Array>.Add 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.
Remark: When declaring an array of N by M elements, this array contains N empty elements. For example, the array declared below contains 3 empty strings. MyArray is array of 3 strings
When adding an element ( <Array>.Add), this element is automatically added after the elements already found in the array. In our example, the added element will correspond to the 4th element. Adding an element to an advanced array property When <Array>.Add 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 as parameter. If no value is passed as parameter, the element is initialized with the default value of the type of the array elements.
Adding an element into a list When <Array>.Add 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.
Adding an array into an array (concatenation) When <Array>.Add is called: - the array is automatically resized to include the new elements. The elements of <WLanguage variable to concatenate> are added at the end of <WLanguage variable>.
- the two arrays must have the same type.
- the arrays must have the same dimension.
- the array dimensions (other than the first dimension) must be identical.
For example: - Correct code:
t1 is array of * by 2 int = [[1,2],[3,4]] t2 is array of * by 2 int = [[5,6],[7,8],[9,10]] t1.Add(t2)
- Invalid code:
t1 is array of * by 3 int = [[1,2],[3,4]] t2 is array of * by 2 int = [[5,6],[7,8],[9,10]] t1.Add(t2)
Adding a list into a list (concatenation) When <Array>.Add is called: - the list is automatically enlarged to receive the new elements. The elements of <WLanguage variable to concatenate> are added at the end of <WLanguage variable>.
- both lists must be of the same type.
Adding the content of a structure to an array of structures without using a variable of the structure If you are using an array of structures with few members, it may be easier to directly add a structure by using the [ ] operator (square brackets). For example, for the following structure: // Structure to store a letter and its ASCII code STKey is Structure sKey is string nAsciiCode is int END // Array of structures arrKeys is array of STKey
In most cases, content is added by using a variable of a type declared in the structure: // Temporary structure for the addition stAKey is STKey // Stores the letter A stAKey.sKey = "A" stAKey.nAsciiCode = Asc("A") arrKeys.Add(stAKey)
With the [ ] operator, you get better legibility:
// Stores the letter A arrKeys.Add(["A", Asc("A")])
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 <Array>.Add.
This function cannot be used on: - non-created arrays.
- fixed arrays.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|