ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / Declaring variables
  • Global scope
  • Local scope
  • Summary scope diagram
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
Variables can be declared anywhere in the code. However, depending on where they are declared, variables cannot be used to perform processes or calculations. This is referred to as scope of variables.
Two types of scope are available:
  • Global.
  • Local.
Global scope
Global means that the variable is visible from anywhere in the code. The variable is visible outside the event (or process) where it was declared. Several levels are available:
  • Project and Set of procedures,
  • Window, Mobile Window, Page, Report,
  • Control.
A variable declared at the project level has the greatest visibility in the program. In this case, the variable is declared in the project initialization event. The variable is visible everywhere, in all the events and processes of the program. However, it is not recommended to declare too many variables with this scope: the memory used by the variable is always reserved even if the variable is not used. Using a large number of global variables is not recommended in the program architecture. To pass variables to an event or a process, it is recommended to use parameters (for more details, see "Parameters and result of the procedure").
A variable declared at the set of procedures and project level have the same visibility. The advantage of declaring a variable at the Set level is to group (or classify) the variables by theme to make the project initialization event easier to read.
A variable declared at the Window, Mobile Window, Page or Report level limits the scope of the variable to the events or processes of that element and its controls. This makes it possible to encapsulate and limit their use.
A global variable declared at the control level limits the scope of the variable to the events of that control. This allows you to group the variables by control and to make the window initialization event easier to read.
By default, global variables are colored in blue in the code editor. To identify global variables and their scope, it is recommended to follow a standard.
Local scope
Local means that the variable has a limited visibility in the code. The variable is visible in the process where it was declared. This makes it possible to restrict the use of the variable to the process or event.
Summary scope diagram
Variable scope
By default, variables are global when they are declared:
  • in the initialization event of the project (or in the "Declaration" event of the set of procedures). The variable is global to the project.
  • in the "Global declarations" event of the window, page or report. The variable is global to the element (window, page or report) where it was declared.
In all other cases, a variable is local to the process or event where it is declared.
Caution: Declare a variable using the "GLOBAL" keyword in the initialization event of a control to make the variable global to that control.
Minimum version required
  • Version 14
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/12/2023

Send a report | Local help