ReadSeq

Reads a line of data from a file opened for sequential processing. Not available in expressions.

Syntax

ReadSeq variable From file.variable[On Error statements]
{[Then statements [Else statements ] | [Else statements ]}

ReadSeq variable reads data from the current position in the file up to a newline and assigns it to variable.

From file.variable identifies the file to read. file.variable must have been assigned in a previous OpenSeq statement. If file.variable is a null value, or the file is not found, or the file is not open, it generates a runtime error.

On Error statements specifies statements to execute if there is a fatal error while the file is being processed. A fatal error occurs if the file cannot be opened or if file.variable is a null value.

Then statements specifies the statements to execute after the line is read from the file.

Else statements specifies the statements to execute if the file is not readable, or an end-of-file is encountered.

Remarks

The OpenSeq statement sets a pointer to the first line of the file. ReadSeq then:

  1. Reads data from the current position in the file up to a newline.
    1. Assigns the data to variable.
    2. Resets the pointer to the position following the newline.
    3. Discards the newline.

If the connection between client and the computer where the engine tier resides times out, ReadSeq returns no bytes from the buffer, and the operation must be retried.

The Status function returns these values after a ReadSeq operation:

0
The read was successful.
1
An end-of-file was encountered.
2
The connection timed out.
-1
The file was not open.

Any other value is an error number indicating that the On Error clause was taken. If a fatal error occurs, and the On Error clause was not specified:

  • An error message appears.
  • Any uncommitted transactions begun within the current execution environment roll back.
  • The current program terminates.

Example

The following example shows ReadSeq used to process each line of a sequential file:

OpenSeq PathName To FileVar Else
   Call DSLogWarn("Cannot open ":PathName, MyRoutine)
   GoTo ErrorExit
End
Loop
   ReadSeq FileLine From FileVar 
   On Error
      Call DSLogWarn("Error from ":PathName:
      →" status=":Status(),            "MyRoutine")
      GoTo ErrorExit
   End
   Then
* ... process the line we just read
   End Else
      Exit      ;* at end-of-file
   End
Repeat
CloseSeq FileVar