ReadLine

Top  Previous  Next

The ReadLine function reads and returns all the characters from a file that was previously opened with OpenRead for the current line up to the next end-of-line character sequence.

 

This call can be used in conjunction with the GetField functions to extract values from a comma delimited text file.

 

ReadLine will only read the first 512 characters of the line. If there are more characters then the FileManager.PartialLine flag will be set to true, and the next call to ReadLine will return the remaining characters.

 

When not using the optional lineIndex parameter, the file is read sequentially. When using the lineIndex parameter the file can be read random access. But note that this later method is much slower.

 

Syntax

 

lineString = fileManager.ReadLine( fileNumber, [lineIndex] )

 

Parameters

file number

 

file number if more than one file has been opened.

lineIndex

 

optional line Index to return

 

 

 

returns

 

the line as a string

 

Example

VARIABLES: lineString TYPE: String

VARIABLES: fileNumber TYPE: Integer

 

' Open the file.

fileNumber = fileManager.OpenRead( "C:\FileToOpen.txt" )

 

IF fileNumber > 0 THEN

 

   ' Loop reading lines until we reach the

   ' end of the file.

   DO UNTIL fileManager.EndOfFile( fileNumber )

 

       ' Read a line from the current file.

       lineString = fileManager.ReadLine( fileNumber )

 

       ' Print the line

       PRINT lineString

 

   LOOP

 

   ' Close the file.

   fileManager.Close( fileNumber )

 

ENDIF