PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US

  • Managing 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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.
Versions 15 and later
Android This function is now available for the Android applications.
New in version 15
Android This function is now available for the Android applications.
Android This function is now available for the Android applications.
Versions 16 and later
Universal Windows 10 App This function is now available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This function is now available for the Windows Phone applications.
Universal Windows 10 App This function is now available for the Windows Phone applications.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 18 and later
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
WINDEVWEBDEV - Server codeReports and QueriesJavaPHPAjaxUser code (UMC)
// Open an external file
FileID = fOpen("C:\MyDirectories\File.txt", foReadWrite)
IF FileID <> -1 THEN
// Write into this file
ResWrite = fWrite(FileID, "Status report of meeting")
IF ResWrite <> -1 THEN
// ...
END
END
Windows Mobile
// Open an external file
FileID = fOpen("\MyDirectories\File.txt", foReadWrite)
IF FileID <> -1 THEN
// Write into this file
ResWrite = fWrite(FileID, "Status report of meeting")
IF ResWrite <> -1 THEN
// ...
END
END
Syntax

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

<Result> = fWrite(<File Identifier> , <Block to Write> [, <Size to Write>])
<Result>: Integer
  • Number of bytes written into the file.
  • -1 if an error occurred. To find out the error details, use ErrorInfo associated with the errMessage constant.
<File Identifier>: Integer
Identifier of the file to use, defined by fOpen or fCreate.
PHP This parameter must be a variant.
<Block to Write>: Character string (with quotes)
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).
WINDEVWEBDEV - Server codeReports and QueriesWindows MobileAjaxUser code (UMC)

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

<Result> = fWrite(<File Identifier> , <Address of Memory Section> , <Size to Write>)
<Result>: Integer
  • Number of bytes (characters) written into the file,
  • -1 if an error occurred. To find out the error details, use ErrorInfo associated with the errMessage constant.
<File Identifier>: Integer
Identifier of the file to use, defined by fOpen or fCreate.
<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

Managing errors

fWrite generates 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.
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)

Operating mode in Windows Vista (and later)

If this function does not operate properly in Windows Vista (and later), check whether the file used is not found in one of the system directories (Windows directory or "Program Files" directory).
Indeed, in Windows Vista (and later), with the UAC mechanism (User Account Control) enabled, you must have the administrator privileges to handle and/or modify the files found in the system directories (Windows directory or "Program Files" directory).
Programming tip: To handle and/or modify the files without having administrator privileges, you should:
  • avoid writing into the Windows directory or into the "Program Files" directory,
  • use the system directory corresponding to the application (returned by SysDir associated with the srCommonAppData constant).
Note: 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 (RC) with fWrite, all you have to do is use the CR constant.
For example:
ResWrite = fWrite(FileID, "Status report" + CR + "Sales for March 2001")

Position in the file

When opening a file, the current position corresponds to:
  • the first byte of the file (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 run, the current position corresponds to the last byte written.
Related Examples:
WD HTML Export Training (WINDEV): WD HTML Export
[ + ] This example explains how to export data in HTML format with the WLanguage functions.
The following topics are presented in this example:
1/ the functions for managing the external files for generating the HTML file
2/ the operations performed on the HTML tags
3/ the generation of an HTML report
The generation of an HTML page is performed from the data found in a memory table.
By programming
The principle consists in generating a text file with a "HTM" extension. The WLanguage function named "fWrite" will be used.
This example easily writes the text strings by respecting the syntax of the HTML language.
Automatically
The principle consists in creating a report on table based on the memory table that was previously filled.
The printout is requested with an HTML output.
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
Components
WINDEVWEBDEV - Server codeReports and Queries wd230std.dll
Windows Mobile wp230std.dll
Java wd230java.jar
Linux wd230std.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment