PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN

  • Handling errors
  • Operating mode in Windows Vista (and later)
  • 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 into an external file.
Caution: The added elements are not inserted into the external file but they overwrite the existing elements.
WEBDEV - Server codePHPAjax
// Open an external file
FileID = fOpen("C:\MyDirectories\File.txt", foReadWrite)
IF FileID <> -1 THEN
// Write into this file
ResWrite = fWrite(FileID, "Meeting report")
IF ResWrite <> -1 THEN
// ...
END
END
New in version 28
WEBDEV - Server codeAjax
// Open an external file
MyFile is DiskFile
MyFile = fOpen("C:\MyDirectories\File.txt", foReadWrite)
IF NOT ErrorOccurred THEN
// Write into this file
ResWrite = fWrite(MyFile, "Meeting report")
IF ResWrite <> -1 THEN
// ...
END
END
Syntax

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

<Result> = fWrite(<File used> , <Block to write> [, <Size to write>])
<Result>: Integer
  • Number of bytes written into 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
PHP This parameter must be a variant.
<Block to write>: Character string
Block of bytes that must be written into 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).
WEBDEV - Server codeAjax

Writing a memory section into an external file (fast speed) Hide the details

<Result> = fWrite(<File used> , <Address of memory section> , <Size to write>)
<Result>: Integer
  • Number of bytes (characters) written into 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
<Address of memory section>: Address
Address of the memory section that must be written into the file.
<Size to write>: Integer
Size (in bytes) that must be written into the external file (up to 2 Go).
This parameter must be less than or equal to the real size of the element written into the external file. For example, if the size of the element to write is equal to 100 bytes, <Size to write> must be less than or equal to 100 bytes.
If this parameter is less than the real size of the written element, only the specified number of bytes will be written into the external file.
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.
WEBDEV - Server code

Operating mode in Windows Vista (and later)

If this function does not operate properly in Windows Vista (and later), check whether the file or directory used is not in one of the system directories (Windows directory or "Program Files" directory).
In Windows Vista (and later), with the UAC mechanism (User Account Control) enabled, you must have administrator privileges to handle and/or modify the files or directories in system directories (Windows directory or "Program Files" directory).
Programming tip: To handle and/or modify the files or directories without administrator privileges, you should:
  • avoid writing to the Windows directory or to the "Program Files" directory,
  • use the system directory of the application (returned by SysDir with the srAppDataCommun constant, for example).
Remark: In Windows Vista (and later), the virtualization mechanism is used to make the applications compatible with Vista. If the file is created in a system directory without having sufficient rights, this file will actually be created in another directory (C:\Users\<LOGIN>AppData\Local\VirtualStore\Windows\). In this case, the file cannot be shared between several applications.

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: wd280std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment