11 - 397 11 - 397
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
Program Example
10 ' This program converts character strings to numeric values using the VAL function
20 A$="1234"
:
' Defines character strings
30 B$="12.34"
40 C$=" 1234"
50 D$="ABC"
60 E$="&H4F
70 F$="&H4F 56"
80 G$=E$+"12"
90 PRINT VAL(A$)
:
' Converts the character string "1234" to the
numeric value 1234
100 PRINT VAL(B$)
:
' Converts the character string "12.34" to
the numeric value 12.34
110 PRINT VAL(C$)
:
' Converts the character string " 1234" to
the numeric value 1234 ignoring the
leading space
120 PRINT VAL(D$)
:
' Returns 0 because the character string
does not represent a numeric value
130 PRINT VAL(E$)
:
' Treats the character string as the
hexadecimal number 4F and converts it to
the numeric value 79
140 PRINT VAL(F$)
:
' Treats only 4F as a hexadecimal number
and converts it to the numeric value 79,
because there is a space after 4F
150 PRINT VAL(G$)
:
' Treats the character string as the
hexadecimal number 4F12 and converts it
to the numeric value 20242
RUN
1234
12.34
1234
0
79
79
20242
OK
REMARK
See the STR$, HEX$, and OCT$ functions.