The scope of a variable is defined as its
visibility and its lifetime. Visibility means what parts of your program
can access it. Lifetime defines when it is created and when it is destroyed.
In PowerBASIC, there are many choices of scope to afford the maximum flexibility.
You may choose any scope which best fits the needs of your program. When
any variable is created in PowerBASIC, it is automatically initialized.
Local variables are only accessible within a single SUB, FUNCTION, METHOD, or PROPERTY. They are automatically created and initialized each time you enter the procedure. They are automatically destroyed when you exit. This is the default variable scope unless you declare otherwise. | |
Static variables are only accessible within a single SUB, FUNCTION, METHOD, or PROPERTY. They are initialized when your program starts, but retain their value regardless of how many times the procedure is entered and exited. They are destroyed only when the program ends. | |
Global variables are accessible from anywhere in your program. They are initialized when your program starts and are destroyed when the program ends. | |
Threaded variables are accessible from anywhere in your program, but each thread within your program will have its own unique copy of them. They are created and initialized when a thread is created. They are destroyed when the thread ends. Threaded variables are commonly called Thread Local Storage (TLS). | |
Instance variables are accessible from any method or property in a class. Each object will have its own unique copy of them. They are created and initialized when an object is created. They are destroyed when an object is destroyed. |
See Also
LOCAL, GLOBAL and STATIC considerations