44
6 ST LANGUAGE
6.1 Configuration
Precautions
■When an assignment statement is used
• The maximum number of character strings that can be assigned is 255. If 256 or more character strings are assigned, a
conversion error occurs.
• Contacts and coils of the timer type or counter type cannot be used for the left side of an assignment statement.
• The instance of a function block cannot be used for the left side of an assignment statement. Use input variables, input/
output variables, and external variables of the instance for the left side of an assignment statement.
■When an assigned arithmetic operation is used
When an arithmetic operation result is assigned to a variable of the larger data type, convert the variable of the arithmetic
operation to the data type of the left side in advance and execute the operation.
When an arithmetic operation result of 16-bit data (INT type) is assigned to 32-bit data (DINT type)
The arithmetic operation result is the same data type as that of the input operand. Thus, in the case of the above program,
when the operation result of varInt1 * 10 exceeds the range of the INT type (-32768 to +32767), an overflow or underflow
result is assigned to varDint1.
In this case, convert the operand of the operational expression to the data type of the left side in advance and execute the
operation.
■Using the operator "-" for sign inversion in an arithmetic operation
When the operator "-" is used to invert the sign of the minimum value of a data type, the minimum value evaluates to the same
value.
For example, -(-32768), where the operator "-" is used with the minimum value of INT type, evaluates to -32768. Thus, an
unintended result may be produced if the operator "-" is used to invert the sign of a variable whose data type will be
automatically converted.
When the value of varInt1 (INT type) is -32768, and the value of varDint1 (DINT type) is 0.
In the example above, the value of (-varInt1) evaluates to -32768 and -32768 is assigned to varDint2.
When using the operator "-" to invert the sign of a variable in an arithmetic operation, perform automatic conversion of the
data type of the variable before the arithmetic operation. Alternatively, avoid using the operator "-" for sign inversion in the
program.
Performing automatic conversion of the data type before an arithmetic operation
Avoiding the use of the operator "-" for sign inversion
varDint1 := varInt1 * 10; // VarInt1 is a INT type variable, and varDint1 is a DINT type variable.
varDint2 := INT_TO_DINT(varInt1); // INT type variable is converted to DINT type variable.
varDint2 := varDint2 * 10; // DINT type multiplication is performed, and the operation result is assigned.
varDint2 := -varInt1 + varDint1;
varDint3 := varInt;
varDint2 := -varDint3 + varDint1;
varDint2 := varDint1 - varInt1;