Introduction to PowerBuilder

HomePrevious Lesson: User Defaults � Registry Database
Next Lesson: Displaying Help in the Login Window

CONSTANTS in PowerScript

Please recall the is_REGKEY variable we declared to hold the registry key name (We used this variable in Close and Open events to while making registry specific calls). You also might have noticed that, we did not change this variable anywhere in the script; we assigned the value at declaration time itself.

PowerBuilder supports constants. Constant can be any PowerBuilder datatype that allows value assignment at declaration time. For example, we assigned is_REGKEY a value at declaration time. Some datatypes such as BLOB do not allow this and you can�t declare a BLOB constant.

It is a good idea to declare all those variables that you do not intend to change as constants instead of regular variables since constants are efficient; the value is established during compilation, the compiled code uses the value itself, rather than referring to a variable that holds the value. Constants also improve readability. Constants as the name suggests, can�t be changed after declaration; any attempt in doing so will result in compilation errors. A constant is a way of assuring that the declaration is used the way you intend.

Let�s change the is_REGKEY from a regular variable to constant. Go to the Instance variable declaration view and replace the line that has is_REGKEY to the following.
CONSTANT String IS_REGKEY = �HKEY_CURRENT_USER/Software/pms/login�

Even though PowerBuilder is case insensitive, typically constants are named in uppercase.
HomePrevious Lesson: User Defaults � Registry Database
Next Lesson: Displaying Help in the Login Window