Syntax of a variable declaration
Contents
Simple syntax
In its simplest form, a PowerScript variable declaration requires
only two parts: the datatype and the variable name. For example:
|
1 |
datatype variablename |
Full syntax
The full syntax allows you to specify access and an initial value.
Arrays and some datatypes, such as blobs and decimals, accept additional
information:
|
1 2 |
{ access } datatype { { size } } { { precision } } variablename { = value } {, variablename2 { = value2 } } |
|
Parameter |
Description |
|---|---|
|
access (optional) |
(For instance variables only) Keywords specifying |
|
datatype |
The datatype of the variable. You can specify a For blobs and decimals, you can specify |
|
{ size } (optional) |
(For blobs only) A number, enclosed in braces, If |
|
{ precision } (optional) |
(For decimals only) A number, enclosed in braces, |
|
variablename |
The name of the variable (must be a valid You can define additional variables |
|
value (optional) |
A literal or expression of the appropriate datatype Blobs cannot be initialized with a For information, see Initial values for |
Examples
Declaring instance variables
|
1 2 |
integer ii_total = 100 // Total shares date id_date // Date shares were bought |
Declaring a global variable
|
1 |
string gs_name |
Declaring shared variables
|
1 2 |
time st_process_start string ss_process_name |
Declaring local variables
|
1 2 |
string ls_city = "Boston" integer li_count |
Declaring blobs
This statement declares ib_Emp_Picture a blob with an initial
length of zero. The length is adjusted when data is assigned to
it:
|
1 |
blob ib_Emp_Picture |
This statement declares ib_Emp_Picture a blob with a fixed length
of 100 bytes:
|
1 |
blob{100} ib_Emp_Picture |
Declaring decimals
These statements declare shared variables sc_Amount and
sc_dollars_accumulated as decimal numbers with two digits after the
decimal point:
|
1 2 |
decimal{2} sc_Amount decimal{2} sc_dollars_accumulated |
This statement declares lc_Rate1 and lc_Rate2 as decimal numbers
with four digits after the decimal point:
|
1 |
dec{4} lc_Rate1, lc_Rate2 |
This statement declares lc_Balance as a decimal with zero digits
after the decimal point:
|
1 |
decimal{0} lc_Balance |
This statement does not specify the number of decimal places for
lc_Result. After the product of lc_Op1 and lc_Op2 is assigned to it,
lc_Result has four decimal places:
|
1 2 3 |
dec lc_Result dec{2} lc_Op1, lc_Op2 lc_Result = lc_Op1 * lc_Op2 |