|
<< Click to Display Table of Contents >> GLOBAL |
![]() ![]()
|
The GLOBAL statement is used to designate variable names that are to be located in the Global databank. Following a global x; statement, any subsequent use of x (without databank designation) will be understood as global:x.
After Gekko leaves the program file, function or procedure, these global variables live on in the Global databank. Therefore, using GLOBAL or global:x = ... can be practical regarding permanent storage of variables, for instance settings, without polluting the 'normal' databanks.
Use global <all>; to render all variables global. After a global <all>, you can still search for a variable x without databank indication outside of the Global databank by means of the special all: designation (for instance y = all:x;).
See the description of the OPEN statement regarding different types of databanks in Gekko.
See also the similar LOCAL statement, for local variables.
global varnames;
global <all>;
varnames |
Comma-separated list of variables |
ALL |
(Optional). With this option, all following (in the rest of the program/function/procedure) left-hand side variables without explicit databank designation are located in the Global databank. For a variable x that you would like to keep in another databank despite using a global <all>, you may use first:x or another bank designation to circumvent global <all>. |
global x, %y, #z; |
After this, any use of x, %y, or #z (in the present program file, function or procedure) will be interpreted as global:x, global:%y, and global:#z. The Global databank is searched last, if databank searching is active (that is, data- or mixed mode), cf. databank search.
Variables in the Global databank survive for instance READ and CLEAR statements, and the Global databank is practical for storing long-term variables like setting etc. For instance:
global:%per1 = 2010; |
As long as Global is not cleared explicitly (or a RESET or RESTART is issued), %per1, %per2, %path, and %unit would be available. If you want to be absolutely sure that the variable is taken from Global, you can use global:%per1 to refer to the variable.
To avoid all the global: indicators, you may consider this alternative, using a procedure for the global settings:
reset; |