You determine the scope of a PowerScript variable by selecting where you declare it. Instance variables have additional access keywords that restrict specific scripts from accessing the variable.
The following table shows the four scopes of variables.
Scope |
Description |
---|---|
Global |
Accessible anywhere in the application. It is independent of any object definition. |
Instance |
Belongs to an object and is associated with an instance of that object (you can think of it as a property of the object). Instance variables have access keywords that determine whether scripts of other objects can access them. They can belong to the application object, a window, a user object, or a menu. |
Shared |
Belongs to an object definition and exists across all instances of the object. Shared variables retain their value when an object is closed and opened again. Shared variables are always private. They are accessible only in scripts for the object and for controls associated with the object. They can belong to the application object, a window, a user object, or a menu. |
Local |
A temporary variable that is accessible only in the script in which you define it. When the script has finished executing, the variable constant ceases to exist. |
Global, instance, and shared variables can be defined in the Script view of the Application, Window, User Object, or Menu painters. Global variables can also be defined in the Function painter:
Select Declare from the first drop-down list in the Script view.
Select the type of variable you want to declare in the second drop-down list of the Script view.
Type the declaration in the scripting area of the Script view.
You declare local variables for an object or control in the script for that object or control.
You can also declare SQL cursors that are global, shared, instance, or local. Open a specific script or select a variable declaration scope in the Script view and type the DECLARE SQL statement or select Paste SQL from the PainterBar or pop-up menu.