6 - 11 6 - 11
MELSEC-Q
6 I/O Processing of Data Files
Example
1 ' Register data in a random file
2 '
10 OPEN "R-TEST.DAT" AS #1
:
'Generates R-TEST.DAT file and names it as
file number 1
20 FIELD #1,8 AS D$,30 AS H$,2 AS K$,4 AS W$
:
'Assigns the file buffer
30 R = 0
40 R = R+1
:
'Specifies the record number
50 INPUT "Date:";D1$
60 LINE INPUT "Item Name:";H1$
70 INPUT "Quantity:";K1
80 INPUT "Rate(%):";W1
90 LSET D$=D1$
:
'Writes data entered in line 50 into file buffer
100 LSET H$=H1$
:
'Writes data entered in line 60 into file buffer
110 LSET K$=MKI$(K1)
:
'Writes data entered in line 70 into file buffer
120 LSET W$=MKS$(W1)
:
'Writes data entered in line 80 into file buffer
130 PUT #1,R
140 INPUT "Continue? (Y/N)";Y$
150 IF Y$="Y" OR Y$="y" GOTO 40
:
'Repeats data input
160 CLOSE #1
:
'Closes the file
170 END
1 ' Read data from the random file written above
2 '
10 OPEN "R-TEST.DAT" AS #1
:
'Opens R-TEST.DAT file and names it as file
number 1
20 FIELD #1,8 AS D$, 30 AS H$, 2 AS K$, 4 AS W$
:
'Assigns the file buffer
30 FOR R=1 TO LOF(1)
:
'Repeats at the last of random file (value
shown by the LOF function)
40 GET #1,R
:
'Reads data from the random file
50 D1$=D$:H1$=H$
:
'Reads data from the file buffer
60 K=CVI(K$)
70 W=CVS(W$)
80 PRINT D$,H$;K;"quantity",W;"%"
:
'Displays the read data
90 PRINT
100 NEXT R
110 CLOSE #1
:
'Closes file
120 END