AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Sintaxis WLanguage / Declaración de variables
  • Overview
  • How to declare a variable?
  • Declaring a variable
  • Declaring a variable and inializing it
  • Declaring several variables
  • Detailed syntaxes
  • Examples
  • Attributes that can be used when declaring a variable
  • Attribute "useful"
  • Attribute "immutable"
  • Attribute "color"
  • Critical section" attribute
  • How to access the properties of a variable?
  • Syntaxes
  • Example
  • Rule for variable scope
  • Rule
  • Exception
  • Special case: Reports & Queries software
  • Name conflict: ambiguous use of a type
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Overview
A variable is defined by name and type.
The variable type defines the values that can be taken by the variable, its memory footprint and the available operations.
Reminder Each type is identified by a WLanguage keyword. These keywords are reserved words.
This help page presents:
To simplify the declaration of variables, you also have the ability to use the type inference.
How to declare a variable?

Declaring a variable

<Variable name> is <Type>

Declaring a variable and inializing it

<Variable name> is <Type> = <Initial value>

Declaring several variables

<Variable name 1>, <Variable name 2> are <Type>

Detailed syntaxes

<Variable name>:Name of the variable to declare.
<Type>:Type of the variable or type common to the declared variables (see Available types of variables).
<Initial value>: Initial value of the variable (optional). This initial value depends on the type of variable.
Remarks:
  • The a and an keywords are optional.
  • When several variables of the same type are declared and initialized on the same line, only the last variable is initialized.
    To declare and initialize several variables at the same time, use the multiple initialization.
  • It is forbidden to use several variables with the same name in an event/process (regardless of the type of these variables).

Examples

  • Declaring simple variables:
    CustomerName is string
    Counter is int
    Price is real
    i,j,k are int

    The type inference allows you to use the following syntaxes:
    let Amount = 1500.69 // real type
    let City = "Montpellier" // string type
  • Declaration of a variable of type Border:
    MyBorder is Border
Declaring several variables and inializing them
<Variable name 1>, <Variable name 2>, ..., <Variable name N> are <Type>
= (<Initial value 1>, <Initial value 2>, ..., <Initial value M>)
Details of syntax
<Variable name>:Name of the variable to declare.
N represents the number of declared variables.
<Type>:Type common to the declared variables (see Available types of variables).
<Initial value>: Initial value of each variable.
M represents the number of values to assign.
Remarks:
  • The assignments are performed from left to right.
  • If there are fewer variables than values (N less than M), a compilation error will be generated.
  • If there are more variables than values (N greater than or equal to M), only the first variables will be assigned.
  • You also have the ability to assign several variables with different values in a single line of code. For more details, see Multiple assignment.
Examples:
x, y, z are int = (1, 10, 4)
// x is set to 1, y to 10 and z to 4

s, t, p are strings = ("A", "B001")
// s is set to "A", t to "B001" and p to ""
Attributes that can be used when declaring a variable

Attribute "useful"

The "useful" attribute can be used when declaring a variable to specify that it is used in the project. This notation avoids displaying the warning indicating that a local variable is unused. In this case, the following syntax must be used:
<Variable name> is <Type>, useful[ = "Reason"]

<Variable name> is <Type> <useful [ = "Reason"]>
"Reason" is a note for the developer.
Example:
n1 is int, useful = "Variable required by the web service" 

n2 is int <useful = "Variable required by the web service">

Attribute "immutable"

The "immutable" attribute can be used when declaring a variable to indicate that the variable is immutable, i.e. that its value will not change once assigned. Unlike a constant, an immutable value can be defined by the result of a procedure/function. The following syntax must be used:
<Variable> is <Type> = <Value>, immutable

<Variable name> is <Type> <immutable> = <Value>
where Value is the mandatory value of the variable.
Example:
n1 is int = 5, immutable

n2 is int <immutable> = 6

Note The "immutable" attribute is only available for simple variables (string, numeric, Boolean and immutable member).

Attribute "color"

The "color" attribute can be used when declaring a variable to define the variable's color in the code editor. The following syntax must be used:
<Variable name> is a(n) <Type> <color = <Value>>
where Value corresponds to the new color of the variable. This color can correspond to:
  • a pre-defined WLanguage color (LightRed, DarkGreen constants, etc.). For example:
    MyColor is an integer <couleur = RougeClair>
  • a keyword corresponding to the coloring of an element defined in the code editor's themes (see Code editor themes. These keywords are:
    AvertissementColor corresponding to warnings.
    ConstantWLanguageDefault color for WLanguage constants.
    FunctionWLanguageDefault color for WLanguage functions.
    NumberDefault color for numbers.
    StringDefault color for character strings.
    VariableWLanguageDefault color used for variables.

    Example:
    MyColoredChain is TO chain<color = Warning>
  • a color in string form. Example:
    MyParameter is TO string <color = #FF00CC>

Critical section" attribute

Al declarar una variable, se puede asociar a una sección crítica utilizando el atributo critical section.
La sintaxis es la siguiente:
VariableName is VariableType <critical section>

or

VariableName is VariableType, critical section
Las secciones de código que manipulan estas variables deben estar entre las funciones CriticalSectionStart y CriticalSectionEnd.
Special case: Una sección crítica se asocia automáticamente a las variables en las que se realizan operaciones simples, tales como:
  • asignar un valor.
  • recuperar un valor.
  • incrementar, decrementar (+, -, ++, --, +=, -= operadores +, -, ++, --, += -=).
Example:
// Global declarations of WIN_STAT window
gcySum is currency, critical section
gcyMax is currency, critical section
...
// Code run by several threads
cyOrderAmount is currency
...
// atomic operation, the critical section is automatically managed by WLanguage
gcySum += cyAmountOrder

// multiple operation, it is necessary to implement the critical section explicitly
USING CriticalSection(gcyMax) IN
IF cyAmountOrder > gcyMax THEN
gcyMax = cyAmountOrder
END
END

Remarks:
  • El atributo critical section está permitido en:
    • las variables globales del proyecto, conjunto de procedimientos, ventana, página y reporte.
    • las variables locales.
    • los miembros de clases.
    • los arrays: en este caso, el atributo está asociado al array y no a los elementos del array.
  • Las colas y las pilas están protegidas de forma predeterminada: el atributo critical section no es necesario.
How to access the properties of a variable?

Syntaxes

The following syntaxes can be used if the type of variable includes some properties:
  • Assigning a property of the variable:
    <Variable name>.<Property> = <Value>
  • Reading a property of the variable:
    <Variable name>.<Property>

Example

Using properties on a Border type:
// Define the border characteristics
MyBorder is Border
MyBorder.Color = LightRed
MyBorder.Thickness = 5
Rule for variable scope

Rule

The rule for variable scope is as follows:
  • If a variable "global" to the project and a variable "global" to a window have the same name:
    • the variable "global" to the window will be used in all the events or processes of the window and window controls as well as in its "local" procedures.
    • the variable "global" to the project will be used in all the other processes.
  • If a variable "global" to the project and a variable "local" to a process have the same name:
    • the "local" variable will only be used in the process where this variable was declared.
    • the variable "global" to the project will be used in all the other processes.
  • If a variable "global" to a window and a variable "local" to a process of this window have the same name:
    • the "local" variable will only be used in the process where this variable was declared.
    • the variable "global" to the window will be used in all other events or processes of the window and its controls (as well as in its "local" procedures).
    • none of these two variables can be used in the rest of the project.
Note: Variables are specific to the executable, web service or WEBDEV session in which they have been declared.
Compilation option
A compiler option allows you to manage the scope of local variables: Alcance de las variables locales limitadas al bloque actual.
If this option is selected, the local variables will be specific to the block. You cannot use a local variable outside the block in which it is declared. The ending of the variable is run at the end of the block (destructors and freeing memory).
You have the ability to redeclare a variable with the same name in two distinct sub-blocks but you cannot redeclare a variable with the same name in a child sub-block.
This option is selected by default for the new projects.
To modify this option:
  1. Open the project description window. To do so, go to the "Proyecto" tab, "Proyecto" group, and click "Descripción".
  2. On the "Compilation" tab, check or uncheck "Alcance de las variables locales limitadas al bloque actual".

Exception

The rule for variable scope does not apply to the constants and to the Data Source variables.

Special case: Reports & Queries software

  • The variables global to the project can be used in the reports and queries created and/or modified in "Reports & Queries".
  • The items for which "Visible para el usuario final en "Reports and Queries"" is checked in the data model editor can be used in Reports and Queries. If this option is unchecked, the field can only be used indirectly (the user does not have the option of completing the field, and the field is not available in wizards, description windows, etc.).

Name conflict: ambiguous use of a type

A WLanguage type can have the same name as another type added to the project by an imported element (.NET assemby classes, structured web service types, etc.). In this case, use the WL prefix to force the WLanguage type when declaring a variable.
Example:
// Force the use of the WLanguage XMLDocument type
// if the XMLDocument type exists elsewhere 
MyVariable is WL.XMLDocument
Versión mínima requerida
  • Versión 14
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 08/10/2025

Señalar un error o enviar una sugerencia | Ayuda local