Assignment

This is the most basic statement type - the cornerstone of every programming language. It assigns a value to a variable.

Variable = <expr>;

Any GPP variable may be assigned any type of expression (except Boolean expressions).

Full arrays cannot be assigned a value - only individual array members can. If an array member is assigned values, the array index can be any numeric expression, not necessarily a constant.

It is highly recommended to ensure that the type of the variable and the assigned expression are the same (numeric or string). This is proper programming practices. However, GPP accepts type-mismatched assignments, where a string is assigned into a numeric variable or vice versa. The result may be unpredictable if the conversion is not straightforward. For instance, assume X is a numeric variable. The statement X = "3"; will result in X getting the value of 3.0, as expected. But X = "abc"; will assign an unpredictable number to X.

An assignment type mismatch generates a compilation warning.

GPP Compatibility Notes:

In the old GPP, when a string constant was assigned to a string variable, it eliminated any spaces found in the constant. For instance, assigning the string "one two three "resulted in an assigned value of "onetwothree".

This behavior is not maintained in GPP2. Strings are assigned "as is". If the space characters are not wanted, they can be eliminated with the STR_CLEAN function.

Example

X = X_CURPOS + ORIGINX;

Alpha = ACOS (Y / X);

STRAARRY[10] = "Yes";

STRAARRY[I] = STR_LEFT(NAME, 4);

S1 = "one two three ";              // S1 gets "one two three"

 

Some functionality may be dependent on the product package. Contact your Reseller if you require a license.