PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Your version: 01A210067F (WINDEV 21)

  • Other types of arrays
  • Procedure: Declaring an array parameter
  • Passing an array in parameter to a procedure
  • WLanguage functions and arrays
  • Array of arrays, associative array, queue, stack, list
  • Limits: Array elements
  • Arrays in the classes
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
An array is a structured type that is used to group a set of elements of the same type. Each array element can be directly accessed by its subscript.
Versions 16 and later
Universal Windows 10 App This feature is available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This feature is available for the Windows Phone applications.
Universal Windows 10 App This feature is available for the Windows Phone applications.
Versions 18 and later
Universal Windows 10 App This feature is available in Windows Store apps mode.
New in version 18
Universal Windows 10 App This feature is available in Windows Store apps mode.
Universal Windows 10 App This feature is available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Example
// Declares an array initialized with the names of days of the week
DayArray is array of strings = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
// Handles the array
DayArray[2] // Returns "Tuesday"
// Declares an array of integers
ValueArray is array of int
// Fills the array of integers by adding values
Add(ValueArray, 5)
Add(ValueArray, 10)
Add(ValueArray, 15)
// Browses the array values
FOR EACH x OF ValueArray
// x is successively equal to 5, 10, 15
...
END
// Declares an array of integers
ValueArray is array <growth=1> of int
// Enlarges the array to insert the value 1: 10
ValueArray[1] = 10
// Enlarges the array to insert the value 2: 20
ValueArray[2] = 20
// Enlarges the array to insert the value 3: 30
ValueArray[3] = 30
// Browses the array values
FOR EACH x OF ValueArray
// x is successively equal to 10, 20, 30
END
// Declares an array of integers
ValueArray is array <growth=N> of int
// Enlarges the array to insert the value 1: 10
ValueArray[1] = 10
// Enlarges the array to insert the value 5: 50
// The values 2, 3 and 4 are initialized to 0
ValueArray[5] = 50
// Browses the array values
FOR EACH x OF ValueArray
// x is successively equal to 10, 0, 0, 0, 50
END
Versions 20 and later
WINDEVWindowsLinuxUniversal Windows 10 App
// Declare an Array of arrays
arrMyArray is array of strings
nArrIndex is int

nArrIndex = Add(arrMyArray)
Add(arrMyArray[nArrIndex], "January")
Add(arrMyArray[nArrIndex], "300")
nArrIndex = Add(arrMyArray)
Add(arrMyArray[nArrIndex], "February")
Add(arrMyArray[nArrIndex], "600")

Trace(arrMyArray[1,1]) // Displays "January"
Trace(arrMyArray[1,2]) // Displays "300"
New in version 20
WINDEVWindowsLinuxUniversal Windows 10 App
// Declare an Array of arrays
arrMyArray is array of strings
nArrIndex is int

nArrIndex = Add(arrMyArray)
Add(arrMyArray[nArrIndex], "January")
Add(arrMyArray[nArrIndex], "300")
nArrIndex = Add(arrMyArray)
Add(arrMyArray[nArrIndex], "February")
Add(arrMyArray[nArrIndex], "600")

Trace(arrMyArray[1,1]) // Displays "January"
Trace(arrMyArray[1,2]) // Displays "300"
WINDEVWindowsLinuxUniversal Windows 10 App
// Declare an Array of arrays
arrMyArray is array of strings
nArrIndex is int

nArrIndex = Add(arrMyArray)
Add(arrMyArray[nArrIndex], "January")
Add(arrMyArray[nArrIndex], "300")
nArrIndex = Add(arrMyArray)
Add(arrMyArray[nArrIndex], "February")
Add(arrMyArray[nArrIndex], "600")

Trace(arrMyArray[1,1]) // Displays "January"
Trace(arrMyArray[1,2]) // Displays "300"
Syntax
Versions 17 and later

Declaring a one-dimensional array


<Array Name> is array [<growth>] [ [<Dimension 1>] ] <Type of Array Elements>
Example:
arrString is array <growth=N> [10] strings
arrInt is array [5] ints
New in version 17

Declaring a one-dimensional array


<Array Name> is array [<growth>] [ [<Dimension 1>] ] <Type of Array Elements>
Example:
arrString is array <growth=N> [10] strings
arrInt is array [5] ints

Declaring a one-dimensional array


<Array Name> is array [<growth>] [ [<Dimension 1>] ] <Type of Array Elements>
Example:
arrString is array <growth=N> [10] strings
arrInt is array [5] ints
<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:
  • nothing (by 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.
Note: 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 variables.
Versions 20 and later
WINDEVWindowsLinuxUniversal Windows 10 App Note: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.
New in version 20
WINDEVWindowsLinuxUniversal Windows 10 App Note: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.
WINDEVWindowsLinuxUniversal Windows 10 App Note: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.
Versions 17 and later

Declaring an array with several dimensions (up to 10)


<Array Name> is array of [ [<Dimension 1> [, <Dimension 2>]...[, <Dimension 10>]] ] <Type of Array Elements>
Example:
arrString is array [10,20] strings
arrInt is array [3,5,2] ints
New in version 17

Declaring an array with several dimensions (up to 10)


<Array Name> is array of [ [<Dimension 1> [, <Dimension 2>]...[, <Dimension 10>]] ] <Type of Array Elements>
Example:
arrString is array [10,20] strings
arrInt is array [3,5,2] ints

Declaring an array with several dimensions (up to 10)


<Array Name> is array of [ [<Dimension 1> [, <Dimension 2>]...[, <Dimension 10>]] ] <Type of Array Elements>
Example:
arrString is array [10,20] strings
arrInt is array [3,5,2] ints
<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 variables.
Versions 20 and later
WINDEVWindowsLinuxUniversal Windows 10 App Note: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.
New in version 20
WINDEVWindowsLinuxUniversal Windows 10 App Note: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.
WINDEVWindowsLinuxUniversal Windows 10 App Note: 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 variables.
Versions 20 and later
Note: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.
New in version 20
Note: The elements that make up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists.
Note: 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>[Subscript1]

Referring to an element in a two-dimensional array:
<Array Name>[Subscript1, Subscript2]
OR
<Array Name>[Subscript1][Subscript2]

Referring to an element in a n-dimensional array:
<Array Name>[Subscript1,...,SubscriptN]
OR
<Array Name>[Subscript1]...[SubscriptN]
<Array Name>:
Name of the array to use.
<Subscript1>:
Subscript of the element for the 1st dimension.
<Subscript2>:
Subscript of the element for the 2nd dimension.
<SubscriptN>:
Subscript of the element for the Nth dimension (N <= 10).
Note: An array cannot be handled as a whole. For example, an array cannot be assigned to another array.
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 in parameter to a procedure. For example:
// Adds a customer into the array
PROCEDURE AddCustomer(arrCustomer is array of * CCustomer,
sName is string,
sInfo is string)
// Builds the new customer object
c is CCustomer(sName, sInfo)
// Adds the object into the array
Add(arrCustomer, c)
Notes:
  • The type of the elements found in the array passed in parameter must be the same as the one of the declaration.
  • The number of dimensions in the array passed in parameter must be the same as the one of the declaration.
  • The number of elements found in each dimension of the array passed in 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: the checks are performed at run time.

Passing an array in parameter to a procedure

An array can be passed in parameter to a procedure. To do so, use the following syntax:
<Procedure Name>(<Array Name>)
For example:
SuppArray is array of 10 by 50 strings
// Call to the DisplayArray procedure
DisplayArray(SuppArray)

WLanguage functions and arrays

Several WLanguage functions can be used to handle the arrays. You have the ability to perform sorts, searches, etc. See Functions for managing arrays for more details.
Versions 20 and later
WINDEVWindowsLinuxUniversal Windows 10 App

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

The following syntaxes are supported:
<variable> is array of arrays of int
<variable> is array of arrays of 5 int
<variable>  is array of 5 arrays of int
<variable> is array of 5 arrays of 5 int

<variable> is array of fixed arrays of 5 int
<variable> is array of 5 fixed arrays of 5 int

<variable> is array of associative arrays of int
<variable> is array of associative arrays (withDuplicates) of int
<variable> is array of associative arrays (withDuplicates,wlInt) of int
<variable> is array of 5 associative arrays of int
<variable> is array of 5 associative arrays (withDuplicates) of int
<variable> is array of 5 associative arrays (withDuplicates,wlInt) of int

<variable> is array of queues of int
<variable> is array of 5 queues of int

<variable> is array of stacks of int
<variable> is array of 5 stacks of int

<variable> is array of lists of int
<variable> is array of 5 lists of int
New in version 20
WINDEVWindowsLinuxUniversal Windows 10 App

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

The following syntaxes are supported:
<variable> is array of arrays of int
<variable> is array of arrays of 5 int
<variable>  is array of 5 arrays of int
<variable> is array of 5 arrays of 5 int

<variable> is array of fixed arrays of 5 int
<variable> is array of 5 fixed arrays of 5 int

<variable> is array of associative arrays of int
<variable> is array of associative arrays (withDuplicates) of int
<variable> is array of associative arrays (withDuplicates,wlInt) of int
<variable> is array of 5 associative arrays of int
<variable> is array of 5 associative arrays (withDuplicates) of int
<variable> is array of 5 associative arrays (withDuplicates,wlInt) of int

<variable> is array of queues of int
<variable> is array of 5 queues of int

<variable> is array of stacks of int
<variable> is array of 5 stacks of int

<variable> is array of lists of int
<variable> is array of 5 lists of int
WINDEVWindowsLinuxUniversal Windows 10 App

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

The following syntaxes are supported:
<variable> is array of arrays of int
<variable> is array of arrays of 5 int
<variable>  is array of 5 arrays of int
<variable> is array of 5 arrays of 5 int

<variable> is array of fixed arrays of 5 int
<variable> is array of 5 fixed arrays of 5 int

<variable> is array of associative arrays of int
<variable> is array of associative arrays (withDuplicates) of int
<variable> is array of associative arrays (withDuplicates,wlInt) of int
<variable> is array of 5 associative arrays of int
<variable> is array of 5 associative arrays (withDuplicates) of int
<variable> is array of 5 associative arrays (withDuplicates,wlInt) of int

<variable> is array of queues of int
<variable> is array of 5 queues of int

<variable> is array of stacks of int
<variable> is array of 5 stacks of int

<variable> is array of lists of int
<variable> is array of 5 lists of int

Limits: Array elements

  • An array can be made of classes only if these classes have a constructor without parameter (or with optional parameters).
  • An array cannot include:
    • composite variables,
    • arrays.
  • An array cannot be made of composite variables.
  • Java 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:
SystemClass is Class
aDefaultArray is local array of 1 int
END
Related Examples:
Using the arrays Unit examples (WINDEV): Using the arrays
[ + ] Using the array type in WLanguage.
Minimum required version
  • Version 9
This page is also available for…
Comments
Exemplo Array - Ocorrencias
//Quantos Array
n_quantos_array is int=tabListanumeros..Occurrence
Info("Tem "+n_quantos_array+" Array")
//Frances
n_quantos_array_f est entier=tabListanumeros..Occurrence
=====
tabListanumeros is array of 0 int
ArrayAddLine(tabListanumeros,10)
ArrayAddLine(tabListanumeros,5)
ArrayAddLine(tabListanumeros,2)
ArrayAddLine(tabListanumeros,20)
ArraySort(tabListanumeros,asAscending)
FOR x=1 TO ArrayCount(tabListanumeros)
SAI_array+=tabListanumeros[x]+CR
END
//blog com video e exemplo
http://windevdesenvolvimento.blogspot.com.br/2016/02/curso-windev-array-002-quantas.html

////Frances

//tabListanumeros_f est tableau de 0 entier

//TableauAjouteLigne(tabListanumeros_f,10)

//TableauAjouteLigne(tabListanumeros_f,5)

//TableauAjouteLigne(tabListanumeros_f,2)

//TableauAjouteLigne(tabListanumeros_f,20)

//TableauTrie(tabListanumeros_f,ttCroissant)

//POUR x=1 A TableauOccurrence(tabListanumeros_f)

// SAI_array+=tabListanumeros_f[x]+RC

//FIN
De matos AMARILDO
Feb. 27 2016
Another example

//Example Array [N,X]

arrMensajes is array of 1 by 3 strings //GLOBAL

//CODE

ArrayDeleteAll(arrMensajes )

Dimension(arrMensajes ,1,3)

i is int = 1

SQLExec(sQuery,ds)

WHILE SQLFetch(ds) = 0
arrMensajes[i,1] = SQLGetCol(ds, 1) //id
arrMensajes[i,2] = SQLGetCol(ds, 2) //numero
arrMensajes[i,3] = SQLGetCol(ds, 3) //mensaje
i++
END
adrianoboller
Nov. 20 2015
Example Array [N,X]
arrMensajes is array of 1 by 3 strings
i is int = 1
SQLExec(sQuery,ds)
WHILE SQLFetch(ds) = 0
arrMensajes[i,1] = SQLGetCol(ds, 1) //id
arrMensajes[i,2] = SQLGetCol(ds, 2) //numero
arrMensajes[i,3] = SQLGetCol(ds, 3) //mensaje
i++
Dimension(arrMensajes, i, 3)
END
adrianoboller
Feb. 11 2015