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 arrays, queues, stacks and lists
  • Limits: Elements of an array
  • Arrays in classes
  • Adding the content of a structure to an array of structures without using a variable of the structure
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
An array is a structured type used to group together a set of elements of the same type. Each element of the array can be accessed by its index.
Example
// Declares an array initialized with the names of days of the week
DayArray is array of strings = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
// Manipulates the array
DayArray[2] // Returns "Tuesday"
// Declares an array of integers
ValueArray is array of int
// Populates the array of integers by adding values
Add(ValueArray, 5)
Add(ValueArray, 10)
Add(ValueArray, 15)
// Iterates over the values of the array
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
// Enlarge the array to insert the value 1: 10
ValueArray[1] = 10
// Enlarge array to insert value 2: 20
ValueArray[2] = 20
// Enlarge the array to insert value 3: 30
ValueArray[3] = 30
// Iterates over the values of the array
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
// Enlarge the array to insert the value 1: 10
ValueArray[1] = 10
// Enlarge the array to insert the value 5: 50
// The values 2, 3 and 4 are initialized to 0
ValueArray[5] = 50
// Iterates over the values of the array
FOR EACH x OF ValueArray
	// x is successively equal to 10, 0, 0, 0, 50
END
WINDEVWEBDEV - Server codeWindowsLinuxiPhone/iPadIOS WidgetApple WatchMac Catalyst
// 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

Declaring a one-dimensional array (syntax 1)


<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 (syntax 2) Hide the details

<Array name> is array [<growth>] of [<Dimension>] <Type of array elements>
<Array name>:
Name of the array variable to be declared.
<growth>:
Option to expand the array:
  • nothing (default) or "<agrandissement=0>"the array is not enlarged automatically. For example, if the array contains 5 elements and the program accesses element 6 or 100, an execution error will be raised.
  • "<agrandissement>"or "<agrandissement=1>"the array is automatically enlarged by 1 element. For example, if the array contains 5 elements and the program accesses element 6, the array is automatically expanded to manipulate element 6. If the program accesses element 100, an execution error will be raised.
  • "<agrandissement=N>": the array is automatically enlarged by the number of elements required. For example, if the array contains 5 elements and the program accesses element 6, the array is automatically expanded by one element to manipulate element 6; if the program accesses element 100, the array is automatically expanded to manipulate element 100. Intermediate elements are initialized with the default value of the type of the array elements.
WEBDEV - Browser code This feature is not supported.
Note: To enlarge a multi-dimensional array, use the Dimension function..
<Dimension>:
Optional dimension of the array. This parameter can:
  • not specified or * or 0: the array is initialized empty.
  • correspond to a constant value or 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 in the array. See The different WLanguage types.
WINDEVWEBDEV - Server codeWindowsLinuxiPhone/iPadIOS WidgetApple WatchMac Catalyst Note: The elements making up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists..

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


<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 a multi-dimensional array (10 dimensions 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 be declared.
<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 elements.
  • 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 in the array. See The different WLanguage types.
WINDEVWEBDEV - Server codeWindowsLinuxiPhone/iPadIOS WidgetApple WatchMac Catalyst Note: The elements making 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 be declared.
<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 in the array. See The different WLanguage types.
Note: The elements making up the array can also be arrays, fixed arrays, associative arrays, queues, stacks or lists..

Referencing an array Hide the details

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

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

Referencing an element in a n-dimensional array:
<Array name>[Index1,...,IndexN]
OR
<Array name>[Index1]...[IndexN]
<Array name>:
Name of the array to be manipulated.
<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:
// Adds a customer to 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 to the array
Add(arrCustomer, c)

Remarks:
  • The data type of the array elements passed as parameter must be the same as the one used in the declaration.
  • The number of dimensions of the array passed as parameter must be the same as the one used in the declaration.
  • The number of elements 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 the same.
  • No checks are performed at compile time: checks are only 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:
<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 manipulate arrays. You can sort, search, etc. For more details, see Array functions.
WINDEVWEBDEV - Server codeWindowsLinuxiPhone/iPadIOS WidgetApple WatchMac Catalyst

Array of arrays, associative arrays, queues, stacks and lists

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: Elements of an array

  • An array can include classes only if these classes have a constructor without parameters (or with optional parameters).
  • An array cannot include composite variables.
  • WEBDEV - Browser codeAndroidAndroid Widget JavaPHP An array cannot include arrays.
  • Java It is not possible to create arrays of classes or structures.

Arrays in classes

When copying class instances, all the members of the class are copied to the new instance, except for the arrays. Therefore, if the value of an array member is modified, it is also modified in all the instances.
To get an independent array in all class instances, it must be declared as follows:
SystemClass is Class
	aDefaultArray is local array 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 pour mémoriser une lettre et son code ASCII
STTouche is Structure
	sTouche is string
	nCodeAscii is int
END
// Tableau de structures
tabTouches is array of STTouche

In most cases, content is added by using a variable of a type declared in the structure:
// Structure temporaire pour l'ajout
stUneTouche is STTouche
// Mémorise la lettre A
stUneTouche.sTouche = "A"
stUneTouche.nCodeAscii = Asc("A")
tabTouches.Ajoute(stUneTouche)

With the [ ] operator, you get better legibility:
// Mémorise la lettre A
tabTouches.Ajoute(["A", Asc("A")])
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo com oop
Crio uma classe

Ex

ClasseMinhaArray is classe

m_minhaArray is array of st_minhaArray

End

St_minhaArray is structure
Nome is string
Endereco is string
Num is Int
Bairro is string
Cidade is string
Estado is string
Cep is string
End


Para usar em um botão ou procedure ou na abertura de uma janela:

//criando o obj

Obj1 is ClasseMinhaArray

ArrayAdd(Obj1:m_minhaArray)

//Alimentando a array da classe

Obj1.m_minhaArray[1].Nome = “Adriano”

Obj1.m_minhaArray[1].Endereco = “Rua Dr Rene Dinorah da Silveira”

Obj1.m_minhaArray[1].Num = 70

Obj1.m_minhaArray[1].Bairro = “Taruma”

Obj1.m_minhaArray[1].Cidade = “Curitiba”

Obj1.m_minhaArray[1].Estado = “Paraná”

Obj1.m_minhaArray[1].Cep = “82.530-510”

//se precisar limpar
ArrayDeleteAll(obj1:m_minhaArray)
Boller
12 Jun. 2024
Exemplo
ARRAY MULTIDIMENSIONAL VARIAVEL

arrayCadastroFrutas is array of 1 by 4 STRING

ArrayDeleteAll(arrayCadastroFrutas)

Dimension(arrayCadastroFrutas,1,4)

X is int = 1

FOR EACH t000_frutas

arrayCadastroFrutas[X,1]=t000_frutas.t000_frutas_ID

arrayCadastroFrutas[X,2]=t000_frutas.t000_fruta

arrayCadastroFrutas[X,3]=t000_frutas.t000_ordem

arrayCadastroFrutas[X,4]=t000_frutas.t000_status

X++

Dimension(arrayCadastroFrutas, X, 4)

END
Boller
12 Jun. 2024
Exemplo OOP com Array
Class_Oop_Crud is Class

m_painelcontrole is array of st_painelcontrole

END

st_painelcontrole is Structure

gs_NomeJanela is string

end


/////////////-------------------- Open Window:
obj1 is Class_Oop_Crud //criou o objeto // carimbo

ArrayAdd(obj1:m_painelcontrole) //dar a dimensao 1 para o array

obj1.m_painelcontrole[1].gs_NomeJanela = MyWindow..Name

/////////////--------------------Button
Info(obj1.m_painelcontrole[1].gs_NomeJanela)
Boller
17 Apr. 2024
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: 10/04/2024

Send a report | Local help