Introduction to PowerBuilder

HomePrevious Lesson: Identifiers
Next Lesson: Standard Data Types

Variable Declarations

Variables have to be declared before they are used in the PowerScript code. Compiling a script in which a variable is used even before it was declared, gives the following error message:

The following is the syntax for declaring a variable.
<Data Type> <Variable Name> = [<Variable Value>]

For example, in the above script, we want to declare the counter and total variables as integers:
integer li_counter
integer li_total = 0

The variable initialization is optional. In the above example, the initial value for li_total variable can be left off, as PowerBuilder assigns a default value of zero to integer data types.

By default, string data types are assigned an initial value of "" and Boolean data types a value of FALSE.

You can also declare multiple variables of the same type in a single line separated by comma, although we do not recommend doing it:
integer li_counter, li_total = 0
HomePrevious Lesson: Identifiers
Next Lesson: Standard Data Types