Click or drag to resize

FReadLine Function

X#
Read a line from an open file.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION FReadLine(
	ptrHandle,
	nMax
) AS STRING CLIPPER
Request Example View Source

Parameters

ptrHandle (Optional)
Type: Usual
The handle of the file to read from.
nMax (Optional)
Type: Usual
The maximum number of characters to read per line. FReadLine() will read until a hard carriage return (Chr(13)) is reached, end-of-file is encountered, or nMax characters are read.
The default value for nMax is 256.

Return Value

Type: String
The line read. When the end-of-file is reached, FReadLine() returns a NULL_STRING and FError() is set to 257.
Remarks
This function is the same as FGets(). Both functions are assumed to handle raw binary data and are not dependent upon the status of SetAnsi(). FReadText() and FRead4(), on the other hand, are dependent upon SetAnsi().
Examples
This example uses FReadLine() to read an entire file without specifying a value for nMax:
X#
1ptrHandle := FOpen2("docs.txt", FO_READ)
2IF ptrHandle != F_ERROR
3    DO WHILE !FEOF(ptrHandle)
4        ? FReadLine(ptrHandle)
5    ENDDO
6ENDIF
7FClose(ptrHandle)
The following example provides a utility that displays and counts all occurrences of a string within a file:
X#
 1FUNCTION Grep(cSearch, cFile AS STRING) ;
 2        AS DWORD PASCAL
 3    LOCAL handle AS PTR
 4    LOCAL Count AS DWORD
 5    LOCAL Line AS STRING
 6    Line := " "
 7    handle := FOpen2(file, FO_READ)
 8    cSearch := Upper(cSearch)
 9    DO WHILE !FEOF(handle)
10        line := Upper(FReadLine(handle))
11        IF InStr(cSearch, line)
12            ? line
13        Count += 1
14        ENDIF
15    ENDDO
16    RETURN Count
See Also