Navigation:  Programming > Structured Text > Concepts >

Variables

Previous pageReturn to chapter overviewNext page

Global Variables

 

Global variables are declared in a specific file (Text) and can be accessed from any part of the program. Their declaration must begin with the keyword VAR_GLOBAL and end with END_VAR.

 

It is also possible to declare retentive global variables using the keyword RETAIN, so that their values are preserved even after the device is restarted. Additionally, global constants can be defined using the keyword CONSTANT, representing fixed and immutable values during program execution.

 

new_st_variables_2

 

Local Variables

 

Local variables are declared within the same block of code where they are used. Their declaration must be grouped, starting with the keyword VAR and ending with END_VAR.

 

These variables are accessible only within the scope in which they are declared, meaning they cannot be used by other parts of the program. This ensures better control over memory usage and helps prevent conflicts between different sections of code.

 

new_st_variables_1

 

 

wpshelp_common_fig_note

NOTE!

 

ยน There is no distinction between uppercase and lowercase letters in variable names (case-insensitive).