Global Variables

Variables declared outside procedures and functions are called Global variables. A global variable's scope covers the entire program from the point at which it is declared.

The disadvantage of global variables is that the programmer has to carefully control their use within a large program to ensure that their values will not change unexpectedly before they are used. Using a global variable within a procedure or function ruin the function's portability (e.g., you cannot copy the procedure or function into another program without also copying the variable declaration at some other point in the program). You must also simulate the initial setting of the global variable in your new program.

DataFlex variable naming convention suggests that you prefix all of your global variables with a "g". This will help you to easily identify global variables within your program. It is also recommended to use the global_variable command to make the declaration unambiguous.

Examples of global variable declarations are:

Global_Variable Integer giCount

Global_Variable String  gsCommandLine

Setting the Maximum Length of a Global String

In DataFlex global strings have a default length of 80 characters. This can be increased to an absolute maximum of 4096 characters when the variable is first declared. The syntax for defining a long global string is:

Global_Variable String {variable-name} {maximum-length}

where {variable-name} is the name of the global string variable that is being declared; and {maximum-length} is the maximum number of characters that the global string can contain. The maximum length must be between 1-4096.

An example of declaring a long global string is:

Global_Variable String gsCommandLine 255

Notes

Global string variables can only contain a maximum of 80 characters by default and an absolute maximum of 4096 characters. The Set_Argument_Size command has no effect on global strings.

See Also

Declaring Variables

Local Variables

Data Types, Variables and Constants