Top  >  Lycia reference  >  Querix 4GL  >  Statements  >  READ

READ

 

READ statement is used to read from the file and to record the read values into the corresponding program variables.

 

 

Element

Description

Descriptor

An integer variable storing the file descriptor

Variable List

A list of variables separated by commas that will accept the values read from the file

 

The READ statement reads from the file previously opened by the OPEN FILE statement. While the file is open, each new READ statement reads the file further from the location the previous READ statement ended reading. Closing and opening the file again will reset the reading offset and the reading will start at the beginning of the file.

 

There is no markers that define the end of the read file. The status variable does not change its value from 0, if a READ statement tries to read a non-existent value and goes beyond the end of file. So if you try to read a file in a loop checking that the status variable is 0, the loop will never end. The value into which a non-existent value tries to be read will not change its contents and will not be assigner NULL as the result.

 

 

Variable list

 

Variables into which the values are read should be compatible with these values, otherwise a conversion error will occur. Each variable will accept a value between the specified delimiters, that depend on the file format and the delimiters set.

 

When reading from a "load" file format, each variable will contain a value between the delimiters (| by default). The escape symbol for the delimiter is backslash (\).The newline characters will be ignored. E.g. the following unl file contains 4 values that will be recorded in to the variables by the READ statement:

 

John|Smith|

Sam|Vimes|

...

READ FROM file_dscr INTO fname1, lname1, fname2, lname2

 

When reading a csv file, each variable will contain a value between commas, because comma is the default separator for csv file format. The newline characters will be ignored.

 

John,Smith,

Sam,Vimes,

...

READ FROM file_dscr INTO fname1, lname1, fname2, lname2

 

When reading from a text file, each variable will contain a new line, since the newline character works as the default separator:

 

John Smith - line 1

Sam Vimes - line 2

...

READ FROM file_dscr INTO line1, line2

 

It is possible to use records and arrays as the variables in the INTO clause:

 

READ FROM file_dscr INTO my_rec.*

READ FROM file_dscr INTO my_array