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
For details, see Data Types.
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