Assigning Variables
- Updated2025-10-31
- 3 minute(s) read
Assign variables using simple assignment, tuple assignment, assignment by value, or assignment by reference.
Simple Assignment
Make assignments in PAscript with the = operator.
Target = Statement
Where Statement is a calculation, a constant, or a function call.
Example
program
section globals
int32 integer
real64 float
text t
endsection
t = "Hello"
integer = 5 * a + 1
float = sin(PI/2)
endprogram
Tuple Assignment
In PAscript, functions can return tuples.
[var_1, var_2, ..., var_n] = functionCall ()
Example
program
section globals
int32 integer
real64 float
text t
endsection
[t, integer, float] = myFunction()
endprogram
function [text a, int32 b, real64 c] = myFunction()
a = "Hello"
b = 2
c = 3.1415
endfunction
Assignment by Value
When you assign a variable by value, a copy of the source value is written to the target value. If the source value changes, the target value still contains the original value.
Use the = operator to assign a simple data type source to a target value. Simple data types include numbers and text.
Example
int32 target = 1 int32 source = 123 target = source // target is assigned the value 123 source = 5 // source is assigned the value 5 while the target remains 123
section globals text text1, text2 endsection text1 = "Hello" // text1 is assigned the value "Hello" text2 = text1 // text2 is assigned the value "Hello" text1 = "world" // text1 is assigned the value "world" while text2 remains "Hello"
Assignment by Reference
When you assign a variable by reference, a copy of the original object is not created. Instead, the reference points directly to the original object. Changes to the source are immediately reflected in the target.
Use the = operator to assign a complex data type source to a target value. Complex data types include all data types except numbers and text.
Example
section globals variant [] table1 endsection variant [10] table2 // Definition local table table2 table2 = table1 // Assignment by reference: table2 is now a synonym for table1 table1:setText(0,"Hello") // Element 0 of table1 and table2 have the value "Hello" table2:setText(1,"world") // Element 1 of table1 and table2 have the value "world"
Reference Keyword
Use the ref keyword to declare simple variables by reference. Simple variables include variables with numeric or text data types.
In addition, use the ref keyword to pass parameters to tasks.
The prefixed keyword ref indicates that the variable is to be assigned to the destination variable as a reference.
ref datatype variableReference [=Initialization]
If you declare a variable with the ref keyword, you must assign that variable to another variable using the ref keyword.
After you assign the variable to reference another variable, you can use the variable in program code. For example, you can set the variable to a value. In this case, both variables have the value.
ref int32 variableReference = ref variable1 variableReference = 5 //both variableReference and variable1 have the value 5
You can assign a variable declared with the ref keyword to another variable at any time. To assign a variable to another variable, call the assignment again with the ref keyword.
Value tables provide references to variables defined in a cell using :getXXXReference() and :setXXXReference() attributes. The int32, real64, and text data types also have helper functions to get references.
Example: ref Keyword
section globals int32 loopCount text fileName endsection int32 loopsValue ref int32 loopReference text fileNameValue ref text fileNameReference // A simple assignment is allowed for loopValue: loopsValue = loopCount // loopReference must be assigned to the reference of a variable before it can be used. // Thus, the following line results in a PAscript error. // loopsReference = loopCount => ERROR // Assign loopsReference to the reference of a variable loopsReference = ref loopCount // Now a simple assignment is allowed loopsReference = loopsValue // loopCount and loopsReference have the value of loopsValue // The same principle applies to the file data type fileNameValue = fileName fileNameReference = ref fileName