READSEQ

READSEQ

Top  Previous  Next

 

The READSEQ statement reads the next field (line of text)from a directory file record previously opened for sequential access.

 

 

Format

 

READSEQ var {ENCODING name} FROM file.var {ON ERROR statement(s)}

{THEN statement(s)}

{ELSE statement(s)}

 

where

 

varis the variable to receive the data read from the file.

 

file.varis the file variable associated with the record by a previous OPENSEQ statement.

 

statement(s)are statement(s) to be executed depending on the outcome of the READSEQ.

 

At least one of the THEN and ELSE clauses must be present.

 

 

The optional ENCODING clause sets the character encoding to be used, overriding any encoding set in the VOC F-type record or when the file was opened. A null string as the encoding name is equivalent to not having the ENCODING clause at all. To disable the default encoding, the encoding name should be specified as "NULL".

 

The next field (line of text) is read into var. If successful, the THEN clause is executed and the STATUS() function would return zero.

 

If there are no further fields to be read, the ELSE clause is executed and the STATUS() function would return ER$RNF (record not found).

 

If a fatal error occurs, the ON ERROR clause is executed. The STATUS() function can be used to establish the cause of the error. If no ON ERROR clause is present, a fatal error causes an abort.

 

The FILEINFO() function can be used with key FL$LINE to determine the field number that will be read by the next READSEQ.

 

 

Example

 

LOOP

  READSEQ REC FROM STOCK.LIST ELSE EXIT

  GOSUB PROCESS.STOCK.ITEM

REPEAT

 

This program fragment reads fields from the record open for sequential access via the STOCK.LIST file variable and calls the PROCESS.STOCK.ITEM subroutine for each field. The loop terminates when the ELSE clause is executed when all fields have been processed.

 

 

See also:

CLOSESEQ, CREATE, NOBUF, OPENSEQ, READBLK, READCSV, SEEK, TIMEOUT, WEOFSEQ, WRITEBLK, WRITECSV, WRITESEQ, WRITESEQF