Data Input/Output In Program - Omron SYSMAC CV500-BSC11 Operation Manual

Basic units
Table of Contents

Advertisement

Data Operations

5-1-5 Data Input/Output in Program

To Simplify Data
Input/Output in Program
To Read DATA Command
Using READ Command
To read data by a program, the INPUT command or substitution statement such
as A = B is used. However, if a large quantity of data is to be handled or if the
input data is known in advance, describing the INPUT command or substitution
statement is inefficient and not necessary. To simplify data input/output in the
program, the READ and DATA commands are used.
The DATA command reads data (constants) continuously to the program. These
data items are automatically read to specified variables by the READ command.
A sample program using the DATA and READ commands is shown below.
10 PARACT 0
20 READ A$; B$
. . . . . . . . . . . . .
30 READ C, D, E
. . . . . . . . . . . .
40 PRINT A$; B$
50 PRINT C; D; E
60 END
70 DATA "BASIC","UNIT"
80 DATA 10, 16, 1990
90 END PARACT
Result of execution
BASIC UNIT
10 16 1990
The READ and DATA commands are always used in pairs. The DATA command
can be described anywhere in the program because it is a non-executable state-
ment. As many DATA commands as required can be used in one program.
An error occurs if
• The number of character constants of the DATA command is read by the nu-
meric variable of the READ command (the numeric constant of the DATA com-
mand can be read as a character string by the character variable of the READ
command),
• The data of the DATA command has run out while the READ command is ex-
ecuted, or
• DATA of another task has been read.
If more than one READ and DATA command exists, data is read in the execution
sequence of the program. However, it may be necessary for the READ command
to read the DATA command on specified line. In this case, the RESTORE com-
mand is used. Note, however, that the DATA command of another task must not
be specified. A sample program using the RESTORE command is shown below.
10 PARACT 0
20 RESTORE 100
30 READ A$, B$
. . . . . . . . . . . . .
40 RESTORE 90
50 READ C, D, E
. . . . . . . . . . . .
60 PRINT A$; B$
70 PRINT C; D; E
80 END
90 DATA 10, 16, 1990
100 DATA "BASIC", UNIT
110 END PARACT
Reads character data from data state-
ment on line 70
Reads numeric data from data state-
ment on line 80
Character data known in advance
. . . .
Numeric data known in advance
. . . . . .
Reads character data from date state-
ment on line 100
Reads numeric data from data state-
ment on line 90
Numeric data known in advance
. . . . . .
Character data known in advance
. . . .
Section 5-1
83

Advertisement

Table of Contents
loading

Table of Contents