ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / External file functions
  • Handling errors
  • Carriage Return at the end of line
  • Position in the file
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
Writes a block of bytes to an external file.
Caution: The added elements are not inserted into the external file but they overwrite the existing elements.
Syntax

Writing a block of bytes to an external file Hide the details

<Result> = fWrite(<File used> , <Block to write> [, <Size to write>])
<Result>: Integer
  • Number of bytes written to the file.
  • -1 if an error occurred. To get more details on the error, use ErrorInfo with the errMessage constant.
<File used>: Integer or DiskFile variable
<Block to write>: Character string
Block of bytes to must be written to the file (up to 2 GB).
The format of the block of bytes is respected. No conversion is performed.
<Size to write>: Optional integer
Size of the string to write (in bytes).
Remarks

Handling errors

fWrite throws an error in the following cases:
  • the file is not opened,
  • the file is not accessible in write mode,
  • the file is locked by another computer or by another application,
  • no disk space is available.

Carriage Return at the end of line

fWriteLine is used to automatically insert a carriage return (CR) at the end of the added line. To insert a Carriage Return (CR) with fWrite, simply use the CR constant.
For example:
ResWrite = fWrite(FileID, "Report" + CR + "Sales - March 2021")

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.
fWrite writes the specified elements from the current position. Once fWrite has been executed, the current position is set to the last byte written.
Remark: To always read the start, you must call fSeek and then fRead.
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: wd290std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 12/20/2023

Send a report | Local help