TAL Programmer's Guide

Assigning Data to Simple Variables
Using Simple Variables
6–4 096254 Tandem Computers Incorporated
Assigning Data to
Simple Variables
After you declare a variable, you can assign a value to it. In the assignment statement,
specify the identifier of a previously declared simple variable, an assignment operator
(:=), and an expression:
INT var; !Declare VAR
var := 345; !Assignment statement
Assigning Variables You can assign an arithmetic expression that contains variables:
INT var1 := 5; !Declare and initialize VAR1
INT var2; !Declare VAR2
var2 := var1 + 10; !Assign result of arithmetic
! expression to VAR2
Matching Data Types Assign values that match the data type of the variable. The assignment value should
be in the range and format described for each data type in “Simple Variables by Data
Type” in this section. For example, if you declare a REAL simple variable, specify an
assignment value in the correct range and format for REAL constants:
REAL num; !Declare NUM, a REAL variable
num := 36.6E-3; !Assign REAL value to NUM
Converting Data Types If necessary you can use type transfer functions to convert the data type of the
assignment value to match the variable. For example, to convert an INT assignment
value to an INT(32) value, use the $DBL standard function:
INT(32) dblwd;
dblwd := $DBL(256); !Convert assignment value to
! match data type of variable
Assigning
Character Strings
You can assign character strings to STRING, INT, and INT(32) variables in assignment
statements. In assignments, the character string can contain one to four ASCII
characters, depending on the variable’s data type. (You can also initialize such
variables with character strings when you declare the variables.)
You cannot, however, assign character strings to FIXED, REAL, or REAL(64) variables,
although you can initialize such variables with character strings when you declare the
variables.