3 - 42 3 - 42
MELSEC-Q
3 LET'S CREATE AND EXECUTE A PROGRAM
(4) Conversion of numbers and characters
The following calculation cannot be performed even if the character string is fully
comprised of numbers.
Example
OK
A$= " 12345"
OK
B=1156
OK
PRINT A$+B
Type mismatch
OK
The VAL function is used when treating a character string comprised of only
numbers as a numeric value. The VAL function converts character strings to
numeric values.
Example
Continued from Example above
A=VAL(A$)
OK
PRINT A+B
13501
OK
Conversely, when handling numeric values as character strings, the STR$
function is used. The STR$ function converts numeric values to character strings.
Example
Continued from Example above
C$=STR$(A+B)
OK
PRINT RIGHT$(C$, 3)
501
OK
Here is a summary of the above points.
"123"
VAL
STR$
123
Characters
Numbers
An Illegal Function Call error will be generated if anything other than
numbers, +, -, E, or • are included in the character string that is to
be converted by the VAL function.