ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage syntax / Declaring variables
  • Other types of arrays
  • Procedure: Declaring an array parameter
  • Passing an array as parameter to a procedure
  • WLanguage functions and arrays
  • Array of arrays, associative array, queue, stack, list
  • Limits: Elements of an array
  • Arrays in the classes
  • Adding the content of a structure to an array of structures without using a variable of the structure
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
An array is a structured type that is used to group a set of elements of the same type. Each element of the array can be accessed by its index.
Example
// Déclare un tableau initialisé avec les noms des jours de la semaine
TableauJour is array of strings = ["Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi"]
// Manipule le tableau
TableauJour[2] // Renvoie "Mardi"
// Déclare un tableau d'entiers
TableauValeur is array of int
// Remplit le tableau d'entiers par ajout des valeurs
Add(TableauValeur, 5)
Add(TableauValeur, 10)
Add(TableauValeur, 15)
// Parcourt les valeurs du tableau
FOR EACH x OF TableauValeur
// x vaut successivement 5, 10, 15
...
END
// Déclare un tableau d'entiers
TableauValeur is array <growth=1> of int
// Agrandit le tableau pour insérer la valeur 1 : 10
TableauValeur[1] = 10
// Agrandit le tableau pour insérer la valeur 2 : 20
TableauValeur[2] = 20
// Agrandit le tableau pour insérer la valeur 3 : 30
TableauValeur[3] = 30
// Parcourt les valeurs du tableau
FOR EACH x OF TableauValeur
// x vaut successivement 10, 20, 30
END
// Déclare un tableau d'entiers
TableauValeur is array <growth=N> of int
// Agrandit le tableau pour insérer la valeur 1 : 10
TableauValeur[1] = 10
// Agrandit le tableau pour insérer la valeur 5 : 50
// Les valeurs 2, 3 et 4 sont initialisées à 0
TableauValeur[5] = 50
// Parcourt les valeurs du tableau
FOR EACH x OF TableauValeur
// x vaut successivement 10, 0, 0, 0, 50
END
WINDEVWEBDEV - Server codeWindowsLinuxUniversal Windows 10 AppiPhone/iPadIOS WidgetApple WatchMac Catalyst
// Déclare un Tableau de tableau
tabMonTableau is array of array of strings
nIndiceTab is int

nIndiceTab = Add(tabMonTableau)
Add(tabMonTableau[nIndiceTab], "Janvier")
Add(tabMonTableau[nIndiceTab],"300")
nIndiceTab = Add(tabMonTableau)
Add(tabMonTableau[nIndiceTab], "Février")
Add(tabMonTableau[nIndiceTab],"600")

Trace(tabMonTableau[1][1]) // Affiche "Janvier"
Trace(tabMonTableau[1][2]) // Affiche "300"
Syntax

Declaring an array to an Dimension( syntax 1)


<Array name> is array [<growth>] [ [<Dimension 1>] ] <Type of array elements>
Example:
tabChaîne is array <growth=N> [10] strings
tabEntier is array [5] int

Declaring an array to an Dimension( syntax 2) Hide the details

<Array name> is array [<growth>] of [<Dimension>] <Type of array elements>
<Array name>:
Name of the array variable to declare.
<growth>:
Optional mode for enlarging the array:
  • no value (default) or "<growth=0>": the array is not automatically enlarged. For example, a runtime error will occur if the array contains 5 elements and if the program accesses the element 6 or 100.
  • "<growth>" or "<growth=1>": the array is automatically enlarged by 1 element. For example, if the array contains 5 elements and if the program accesses the element 6, the array is automatically enlarged to handle the element 6 ; a runtime error will occur if the program accesses the element 100.
  • "<growth=N>": the array is automatically enlarged by the number of necessary elements. For example, if the array contains 5 elements and if the program accesses the element 6, the array is automatically enlarged to handle the element 6 ; if the program accesses the element 100, the array is automatically enlarged to handle the element 100. The intermediate elements are initialized with the default value for this type of array elements.
WEBDEV - Browser code This feature is not supported.
Remark: To enlarge an array with several dimensions, use Dimension.
<Dimension>:
Optional dimension of the array. This parameter can:
  • be unspecified or correspond to * or 0: the array is initialized empty.
  • correspond to a constant value or to an integer variable: the array is initialized with the specified number of elements. Each element is initialized with the default value of its type.
<Type of array elements>:
Type of the elements found in the array. See The different types of WLanguage.
WINDEVWEBDEV - Server codeWindowsLinuxUniversal Windows 10 AppiPhone/iPadIOS WidgetApple WatchMac Catalyst Remark: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.

Declaring a multi-dimensional array (10 maximum) - Syntax 1


<Array name> is array of [ [<Dimension 1> [, <Dimension 2>]...[, <Dimension 10>]] ] <Type of array elements>
Example:
tabChaîne est un tableau [10,20] chaînes
tabEntier est un tableau [3,5,2] entiers

Declaring a multi-dimensional array (10 maximum) - Syntax 2 Hide the details

<Array name> is array of [<Dimension 1> [by <Dimension 2>] ... [by <Dimension 10>]] <Type of array elements>
OR
<Array name> is array of [<Dimension 1> [, <Dimension 2>]... [, <Dimension 10>]] <Type of array elements>
<Array name>:
Name of the array variable to declare.
<Dimension 1>...<Dimension 10>:
Dimension 1 to 10 of the array. The value of the dimension can correspond to:
  • * or 0: the dimension is initialized with 0 element.
  • a constant value or an integer variable: the dimension is initialized with the specified number of elements. Each element is initialized with the default value of its type.
<Type of array elements>:
Type of the elements found in the array. See The different types of WLanguage.
WINDEVWEBDEV - Server codeWindowsLinuxUniversal Windows 10 AppiPhone/iPadIOS WidgetApple WatchMac Catalyst Remark: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.

Declaring an array parameter Hide the details

One-dimensional array:
<Parameter name> is array of [<Dimension>] <Type of array elements>

Two-dimensional array
<Parameter name> is array of <Dimension 1> by <Dimension 2> <Type of array elements>

N-dimensional array
<Parameter name> is array of [<Dimension 1> [by <Dimension 2>] ... [ by <Dimension N>]] <Type of array elements>
<Parameter name>:
Name of the array parameter to declare.
<Dimension n>:
<Dimension> may not be specified, it may correspond to * , 0 or to a constant value.
<Type of array elements>:
Type of the elements found in the array. See The different types of WLanguage.
Remark: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.

Referring to an array Hide the details

Referring to an element in a one-dimensional array:
<Array name>[Index1]

Referring to an element in a two-dimensional array:
<Array name>[Index1, Index2]
OR
<Array name>[index1][index2]

Referring to an element in a n-dimensional array:
<Array name>[Index1,...,IndexN]
OR
<Array name>[Index1]...[IndexN]
<Array name>:
Name of the array to use.
<Index1>:
Index of the element for the 1st dimension.
<Index2>:
Index of the element for the 2nd dimension.
<IndexN>:
Index of the element for the Nth dimension (N <= 10).
Remarks

Other types of arrays

The Array keyword is used to define an array. Other types of "advanced" arrays are available:

Procedure: Declaring an array parameter

An array can be passed as parameter to a procedure. For example:
// Ajoute un client dans le tableau
PROCEDURE AjouteClient(tabClient is array of * CClient,
sNom is string,
sInfo is string)
// Construit le nouvel objet client
c is CClient(sNom, sInfo)
// Ajoute l'objet dans le tableau
Add(tabClient, c)

Remarks:
  • The type of the elements found in the array passed as parameter must be the same as the one of the declaration.
  • The number of dimensions in the array passed as parameter must be the same as the one of the declaration.
  • The number of elements found in each dimension of the array passed as parameter must correspond to the declaration:
    • if the number of elements for the dimension is *, no check is performed.
    • if the number of elements for the dimension is specified, the number of elements must be identical.
  • No check is performed during the compilation: checks are performed at runtime.

Passing an array as parameter to a procedure

An array can be passed as parameter to a procedure. To do so, use the following syntax:
<Nom de la procédure>(<Nom du tableau>)

For example:
TableauFourn is array of 10 by 50 strings
// Appel de la procédure AfficheTableau
AfficheTableau(TableauFourn)

WLanguage functions and arrays

Several WLanguage functions can be used to handle the arrays. You have the ability to perform sorts, searches, etc. For more details, see Array functions.
WINDEVWEBDEV - Server codeWindowsLinuxUniversal Windows 10 AppiPhone/iPadIOS WidgetApple WatchMac Catalyst

Array of arrays, associative array, queue, stack, list

The following syntaxes are supported:
<variable> est un tableau de tableaux d'entiers
<variable> est un tableau de tableaux de 5 entiers
<variable> est un tableau de 5 tableaux d'entiers
<variable> est un tableau de 5 tableaux de 5 entiers

<variable> est un tableau de tableaux fixes de 5 entiers
<variable> est un tableau de 5 tableaux fixes de 5 entiers

<variable> est un tableau de tableaux associatifs d'entiers
<variable> est un tableau de tableaux associatifs (avecDoublon) d'entiers
<variable> est un tableau de tableaux associatifs (avecDoublon,wlEntier) d'entiers
<variable> est un tableau de 5 tableaux associatifs d'entiers
<variable> est un tableau de 5 tableaux associatifs (avecDoublon) d'entiers
<variable> est un tableau de 5 tableaux associatifs (avecDoublon,wlEntier) d'entiers

<variable> est un tableau de files d'entiers
<variable> est un tableau de 5 files d'entiers

<variable> est un tableau de piles d'entiers
<variable> est un tableau de 5 piles d'entiers

<variable> est un tableau de listes d'entiers
<variable> est un tableau de 5 listes d'entiers

Limits: Elements of an array

  • An array can be made of classes only if these classes have a constructor without parameter (or with optional parameters).
  • An array cannot be made of composite variables.
  • WEBDEV - Browser codeAndroidAndroid Widget JavaPHP And array cannot be made of arrays.
  • Java No array of classes or array of structures can be created.

Arrays in the classes

When copying instances of classes, all the members of the class are copied into the new instance except for the arrays. Therefore, if the value of an array member is modified, this value is modified in all the instances.
To get independent arrays in all instances of classes, a local array must be declared as follows:
ClasseSystème is Class
tTableauDéfaut is array local of 1 int
END

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")])
Related Examples:
Using the arrays Unit examples (WINDEV): Using the arrays
[ + ] Using the array type in WLanguage.
Minimum version required
  • Version 9
This page is also available for…
Comments
ARRAY MULTIDIMENSIONAL VARIAVEL
arrayAntes is array of 1 by 4 STRING
ArrayDeleteAll(arrayAntes)
Dimension(arrayAntes,1,4)
X is int = 1
FOR EACH t000_frutas
arrayAntes[X,1]=t000_frutas.t000_frutas_ID
arrayAntes[X,2]=t000_frutas.t000_fruta
arrayAntes[X,3]=t000_frutas.t000_ordem
arrayAntes[X,4]=t000_frutas.t000_status
X++
Dimension(arrayAntes, X, 4)
END
BOLLER
28 Feb. 2024
Novo exemplo de array multi dimensional
ATENÇÃO

arrayAntes is array of 1 by 4 STRING
arrayAntes .Add([dimensão01,dimensão02])

ou

arrayAntes is array of 1 by 4 STRING
Dimension(arrayAntes,1,2)

Isso por que uma Matriz Multidimensional precisa ser iniciada, sem dar a dimensao dela não funciona
Boller
28 Feb. 2024
item limit
I have a customer who is reaching the 65,000 item limit and was wondering if an array counted as one item or that if each element in the array counted towards the total. Like MyArray ["john","mary","frank"] is that one item towards the limit or three?
DECKFURNITURE
29 Mar. 2019

Last update: 03/06/2024

Send a report | Local help