Assignment – PB Docs 126

Assignment

Description

Assigns values to variables or object properties or object
references to object variables.

Syntax

Argument

Description

variablename

The name of the variable or object property
to which you want to assign a value. Variablename can
include dot notation to qualify the variable with one or more object names.

expression

An expression whose datatype is compatible
with variablename.

Usage

Use assignment statements to assign values to variables. To
assign a value to a variable anywhere in a script, use the equal
sign (=). For example:

No multiple assignments

Since the equal sign is also a logical operator, you cannot
assign more than one variable in a single statement. For example,
the following statement does not assign the value 0 to A and B:

This statement first evaluates B=0 to true or FALSE and
then tries to assign this boolean value to A. When A is not a boolean
variable, this line produces an error when compiled.

Assigning array values

You can assign multiple array values with one statement, such
as:

You can also copy array contents. For example, this statement copies
the contents of Arr2 into array Arr1:

Operator shortcuts

The PowerScript shortcuts for assigning values to variables
in the following table have slight performance advantages over their equivalents.

Table 7-1: Shortcuts for assigning values

Assignment

Example

Equivalent to

++

i ++

i = i + 1

i —

i = i – 1

+=

i += 3

i = i + 3

-=

i -= 3

i = i -3

*=

i *= 3

i = i * 3

/=

i /= 3

i = i / 3

^=

i ^=3

i = i ^ 3

Unless you have prohibited the use of dashes in variable names,
you must leave a space before -- and -=. If
you do not, PowerScript reads the minus sign as part of a variable
name. For more information, see “Identifier names “.

Examples

[Example 1]

These statements each assign a value to the variable ld_date:

[Example 2]

These statements assign the parent of the current control
to a window variable:

[Example 3]

This statement makes a CheckBox invisible:

[Example 4]

This statement is not an assignment—it tests the
value of the string in the SingleLineEdit sle_emp:

[Example 5]

These statements concatenate two strings and assign the value
to the string Text1:

[Example 6]

These assignments use operator shortcuts:

These shortcuts can be used only in pure assignment
statements. They cannot be used with other operators in a statement.
For example, the following is invalid:

The following is valid, because ++ is
used by itself in the assignment:


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x