READT Statement

The READT statement reads the next record (block) on the magnetic tape or floppy disk unit, assigning its value to the specified variable.

Format

READT var [RETURNING var]

[THEN

   statements

END] [ELSE

   statements

END]

Parameter(s)

var

Variable into which the next record is read, in dynamic array form.

RETURNING var

If a tape or floppy disk error occurs while using the RETURNING clause, the tape or floppy disk error is assigned to the returning variable and program control continues through the ELSE clause.

THEN statements

Executes statements if record is successfully read.

ELSE statements

Executes statements if record cannot be read.

Description

The READT statement may be used to read a record from an attached tape or floppy disk unit. If a record is read, its value is assigned to the specified variable and the THEN statements are executed. If the record cannot be read, the ELSE statements are executed, and the value of var1 does not change.

A record might not be read because the tape or floppy disk has not been attached, or because an End-Of-File mark was encountered. To determine why a tape or floppy disk could not be read, the SYSTEM function is often used in the ELSE portion of a READT statement. See SYSTEM Function for more information.

READT also has an optional UNLABELED clause to allow 1/2-inch tapes to read a tape without reading a label.

Format

READT var [UNLABELED] [RETURNING var]

[THEN

   statements

END] ELSE

Statements

END

To read tapes or floppy disks in ASCII hexadecimal format, use the READTX statement.

See READTX Statement for more information.

Example

The program segment in this example reads data off a tape and prints them in a readable format. The item-IDs are printed and then each attribute is printed on a separate line, preceded by the attribute number.

LOOP  

   READT NEWRECORD ELSE    

      IF SYSTEM(0) = 2 THEN   

         END.OF.TAPE = TRUE  

      END ELSE    

         PRINT "SYSTEM ERROR --"    

         GOSUB EXIT  

      END   

   END   

   REC.NUM += 1  

UNTIL END.OF.TAPE DO    

   PRINT    

   PRINT "PRESS ANY KEY TO READ RECORD " : REC.NUM :" : " :

   INPUT CHAR,1   

   PRINT    

   NO.OF.ATTRS = DCOUNT(NEWRECORD , AM)    

   FOR I = 1 TO NO.OF.ATTRS  

      PRINT I, NEWRECORD< I >

   NEXT I   

REPEAT

See Also

Statement and Function Reference