11 - 132 11 - 132
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
LOC
Function
LOCation
• Returns the current logical location within a file.
LOC ( <file number> )
Syntax
file number
• • • •
Specify the file number of the file in order to detect its
current location.
Examples
PRINT LOC(1)
• • • •
If file number 1 is a sequential file, the location will be
displayed in increments of 256 bytes. If file number 1
is a random file, the record number last accessed will
be displayed.
Description
• The LOC function returns the current logical location within a file.
• The value returned by the LOC function will differ depending on the type of the specified
file in <file number>.
For sequential files
The number of records that have been read/written (one record = 256 bytes) since the file
was opened will be returned as the function value.
For random files
The record number accessed last by the GET or PUT instruction will be returned as the
function value.
Program Example
10 ' Finds the record number in which data is written to a random file
20 OPEN "LOC.DAT" AS #1
: ' Opens the file
30 FIELD #1,8 AS CS$, 10 AS AR$, 4 AS CL$, 10 AS NA$
:
' Assigns a variable region in the random
file buffer
40 INPUT "CALLSIGN";C$:LSET CS$=C$
: ' Enters data
50 INPUT "AREA ";A$:LSET AR$=A$
60 INPUT "CLASS ";B$:LSET CL$=B$
70 INPUT "NAME ";N$:LSET NA$=N$
80 PUT #1
:
' Writes to file
90 PRINT LOC(1); "Station number"
:
' Displays record number written by the
PUT instruction
100 INPUT "Continue registration? (Y/N)";Y$
:
' Y or N is input
110 IF Y$="Y" OR Y$="y" THEN 40
:
' Continues registration if Y
120 CLOSE #1
:
' Closes the file
REMARK
See the EOFand LOF functions.