ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / External file functions
  • Handling errors
  • Position in the file
  • ANSI/Unicode management
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Reads a line in an external file.
PHP In this version, it is only possible to read lines in external files in ANSI format.
WINDEVWEBDEV - Server codeReports and QueriesJavaUser code (UMC)PHPAjax
// Ouverture d'un fichier externe
IDFichier is int
ResLecture is string
IDFichier = fOpen("C:\MesRépertoires\Fichier.txt", foReadWrite)
IF IDFichier <> -1 THEN
	// Lecture d'une ligne dans ce fichier
	ResLecture = fReadLine(IDFichier)
	...
END
WINDEVWEBDEV - Server codeReports and QueriesJavaUser code (UMC)Ajax
// Ouverture d'un fichier externe
MonFichierTxt is DiskFile
ResLecture is string
MonFichierTxt = fOpen("C:\MesRépertoires\Fichier.txt", foReadWrite)
IF NOT ErrorOccurred THEN
	// Lecture d'une ligne dans ce fichier
	ResLecture = fReadLine(MonFichierTxt)
	...
END
Syntax

Reading a file line by line Hide the details

<Result> = fReadLine(<File used> [, <Separator>])
<Result>: Character string or Unicode character string
  • Line read in an external file.
  • EOT constant if the end of file has been reached.
  • Empty string ("") if an error occurred. In this case, the ErrorOccurred variable is set to True.
Note: A line ends with a carriage return (CR).
PHP This parameter must be a character string.
<File used>: Integer or DiskFile variable
PHP This parameter must be a variant.
<Separator>: Character string
Separator used between the lines. The default separator is the Carriage Return (CR).
PHP This parameter is not available. The separator used is the Carriage return (CR).
WINDEVWEBDEV - Server codeReports and QueriesiPhone/iPadIOS WidgetJavaUser code (UMC)Ajax

Reading a file line by line using a procedure Hide the details

<Result> = fReadLine(<File used> , <WLanguage procedure> [, <Separator>])
<Result>: Integer
Number of lines read.
Note: A line ends with a carriage return (CR).
<File used>: Integer or DiskFile variable
PHP This parameter must be a variant.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure ("callback") called for each line read in the file. This procedure is used to manipulate the current line. For more details on this procedure, see Parameters of the procedure used by fReadLine.
<Separator>: Character string
Separator used between the lines. The default separator is the Carriage Return (CR).
PHP This parameter is not available. The separator used is the Carriage return (CR).
Remarks

Handling errors

fReadLine throws an error in the following cases:
  • the file is not opened,
  • the file is not accessible in read mode,
  • the file is locked by another computer or by another application. fUnlock is used to unlock an external file.

Position in the file

When opening a file, the current position corresponds to:
  • the first file byte (by default),
  • the last byte of the file is the file is opened in "addition" mode (foAdd constant).
This position can be modified by fSeek.
fReadLine reads the specified elements from the current position. Once fReadLine has been executed, the current position is set to the last byte read. fReadLine returns the EOT constant if the end of the file has been reached.
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)Ajax

ANSI/Unicode management

The fReadLine function reads:
  • a Unicode string in a Unicode file.
  • an Ansi string in an Ansi file.
The file is created or opened with fCreate/fOpen by specifying the file type.
Depending on the format of the external file used, some conversions are required once a character string was read in an external file:
Current computer
External file
in ANSI format
(fOpen or fCreate associated with the foAnsi constant)
External file
in Unicode format
(fOpen or fCreate associated with the foUnicode constant)
fReadLine functionPC running WindowsRead operation in ANSI format
Can be converted to Unicode using AnsiToUnicode function
MobileReading in Unicode format
Conversion to ANSI possible with UnicodeToAnsi

Remark: If the result of the fReadLine function in an ANSI file is assigned to a Unicode string (and vice versa), the conversion will be implicitly performed.
For more details, see Unicode management
Related Examples:
Handling text files Unit examples (WINDEV): Handling text files
[ + ] Handling "text" files with WINDEV:
- Create a text file
- Write into a text file
- Read in a text file
Handling text files Unit examples (WEBDEV): Handling text files
[ + ] This example explains how to handle "non HFSQL" files with WEBDEV and it allows you to:
- Create a text file
- Write into a text file
- Read in a text file
Handling text files Unit examples (WINDEV Mobile): Handling text files
[ + ] Handling external "text" files:
- Create a text file
- Write into a text file
- Read in a text file
Business / UI classification: Business Logic
Component: wd300std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/24/2024

Send a report | Local help