Advanced PowerBuilder

HomePrevious Lesson: Variables & Scoping
Next Lesson: Access Levels - Variables

Name Spaces

You can declare a global variable and a local variable with the same name. In such cases, in versions prior to 5.0, you can't access the global variable from the script in which the local variable is declared with the global variable name. With version 5.0, compiler gives you an informational message, and you can access both as shown below, even when their names are same:
var1 = 100 // Sets the local variable
::var1 = 200 // Sets the global variable

"::" (double colon) is the global scope operator and allows accessing global variable from the script in which the same variable is declared as a local.

If you have declared an instance and global variables with same name, referring to them without any prefix would refer to the global variable. Note that, doing the same with local and global variables would refer to the 'local' variable and not the global. You need to use THIS pronoun to access the instance variable.
// Global and instance variables are declared with same name.
This.var1 = 100 // Sets instance variable
var1 = 100 // Sets global variable
::var1 = 100 // Sets global variable
// Global, instance and local variable are declared same.
This.var1 = 100 // Sets instance variable
var1 = 100 // Sets local variable
::var1 = 100 // Sets global variable 
HomePrevious Lesson: Variables & Scoping
Next Lesson: Access Levels - Variables