Global variables
Global variables can be shared between all functions in a project. The Global instruction is used to declare a global variable.
To declare global variables in a program, use the Global instruction with the desired variable type (Boolean, Byte, UByte, Integer, Short, UShort, Long, Int32, UInt32, Int64, UInt64, Real, Double, String) at the beginning of the program before any Function statements:
Boolean, Byte, UByte, Integer, Short, UShort, Long, Int32, UInt32, Int64, UInt64, Real, Double, String
See details below.
Add "Static" or "NonStatic" to the beginning of the declaration to change the initialization timing.
If not specified: Based on the setting in [Setup]-[System Configuration]-[Controller]-[Initialize global variables when function starts].
See details below.
[Setup]-[System Configuration]-[Controller]-[Preferences] Page
Static: Initialization occurs when first executing the main function after Controller startup.
NonStatic: Initialization occurs when the executing the main function.
TIP
To indicate that variables are global, precede the name with “g_” as shown in the example below. With this, you can improve the program readability.
Program: MAIN.PRG
Global Integer g_TotalCycles
Function main
Call LoadPart
...
...
Fend
Program: LOADPART.PRG
Function LoadPart
Jump pick
On gripper
Wait .1
Jump place
Off gripper
Wait .1
g_TotalCycles = g_TotalCycles + 1
Fend