6 - 6 6 - 6
MELSEC-Q
6 I/O Processing of Data Files
Example
1 ' Register data to a sequential file
2 '
10 OPEN "0:TEST.DAT" FOR OUTPUT AS #1
: 'Generates TEST.DAT file and names it as file
number 1
20 INPUT "Date:";D$
30 LINE INPUT "Item Name:";H$
40 INPUT "Quantity:";K
50 INPUT "Rate (%):";W
60 PRINT #1,D$;",";
:
'Data entered in line 20 is written into the file
70 PRINT #1,CHR$(&H22);H$;CHR$(&H22);",";
:
'Data entered in line 30 is written into the file
80 PRINT #1,K;",";
:
'Data entered in line 40 is written into the file
90 PRINT #1 USING "###.#";W
:
'Data entered in line 50 is written into the file
100 INPUT "Continue? (Y/N)";Y$
110 IF Y$="Y" OR Y$="y" GOTO 20
:
'Repeats data input
120 CLOSE #1
:
'Closes the file
130 END
1 ' Read data from the sequential file written above
2 '
10 OPEN "0:TEST.DAT" FOR INPUT AS #1
:
'Opens the TEST.DAT file using input mode
and names it as file number 1
20 IF EOF(1) GOTO 100
:
'Ends program when the end of file is
detected
30 INPUT #1, D$
:
'Reads date written in the file
40 INPUT #1, H$
:
'Reads item name written in the file
50 INPUT #1, K
:
'Reads quantity written in the file
60 INPUT #1, W
:
'Reads rate written in the file
70 PRINT D$,H$,K:"quantity",W:"%"
:
'Displays data that has been read
80 PRINT
90 GOTO 20
100 CLOSE #1
:
'Closes the file
110 END