3 - 21 3 - 21
MELSEC-Q
3 LET'S CREATE AND EXECUTE A PROGRAM
3.5.2 Preparing groups of data
Use the READ and DATA instructions in order to prepare a group of data to be
assigned. These instructions use the READ instruction to obtain the data specified by
the DATA instruction. Try executing the following example.
10 READ A, B, C, D
20 PRINT A, B, C, D
30 DATA 35, 6, -8, 12
RUN
35 6 -8 12
OK
The variables following the READ instruction
correspond to the values following the DATA
instruction as shown below.
35
A
6
B
- 8
C
12
D
The DATA instruction will be read properly by the READ instruction no matter where
they are placed and no matter how scattered they are. In addition, any character
strings can be used.
"51H"
A$
"MEE"
B$
"TD"
C$
"PC"
D$
…
"MTC"
BM$
CM$
However, the following program has a problem.
10 DATA 51H
20 READ A$, B$, C$
30 DATA MEE
70 DATA TD
80 READ D$
90 DATA PC
10 DATA MTC
20 READ BM$, CM$
?
There isn't anything
that corresponds
to CM$.
…
…
As shown above, an error will be generated if the DATA instruction does not include a
value that corresponds to a READ instruction.
If a numeric value is specified by the DATA instruction, the following will occur
depending on the variable specified by the READ instruction that reads that data.
"7"
A$
10 READ A$, B%
20 DATA 7, 7
If a character variable is
specified by the READ
instruction, it is treated
as a character string.
If a numeric variable is
specified by the READ
instruction, it is treated
as a numeric value.
7
B%