ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / External file functions
  • Handling errors
  • Position in the file
  • Managing the ANSI/UNICODE format
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Reads a line in an external file.
Example
WINDEVWEBDEV - Server codeReports and QueriesJavaUser code (UMC)Ajax
// Open an external file
MyTextFile is DiskFile
ResRead is string
IF MyTextFile.Open("C:\MyDirectories\File.txt", foReadWrite) = True THEN
// Read a line in this file
ResRead = MyTextFile.ReadLine()
...
END
Syntax

Reading a file line by line Hide the details

<Result> = <File used>.ReadLine([<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.
Remark: A line ends with a CR character (Carriage Return).
<File used>: DiskFile variable
Name of the DiskFile variable initialized with fOpen or fCreate.
<Separator>: Character string
Separator used between the lines. The default separator is the Carriage Return (CR).
New in version 2024
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.
Remark: A line ends with a CR character (Carriage Return).
<File used>: Integer or DiskFile variable
Name of the DiskFile variable initialized with fOpen or fCreate.
<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).
Remarks

Handling errors

<DiskFile variable>.ReadLine 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. <DiskFile variable>.Unlock 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 <DiskFile variable>.Seek.
<DiskFile variable>.ReadLine reads the specified elements from the current position. Once <DiskFile variable>.ReadLine has been executed, the current position is set to the last byte read. <DiskFile variable>.ReadLine returns the EOT constant if the end of the file has been reached.
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)Ajax

Managing the ANSI/UNICODE format

The <DiskFile variable>.ReadLine 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)
<DiskFile variable>.ReadLine functionPC running WindowsRead operation in ANSI format
Conversion to UNICODE possible with <String type>.AnsiToUnicode
MobileRead operation in UNICODE format
Conversion to ANSI possible with UnicodeToAnsi

Remark: If the result of <DiskFile variable>.ReadLine of an ANSI file is assigned to a UNICODE string (and vice versa), the conversion will be implicitly performed.
For more details, see Managing UNICODE
Business / UI classification: Business Logic
Component: wd290std.dll
Minimum version required
  • Version 28
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/02/2023

Send a report | Local help