Write

File management function.

The Write function writes data to the specified file.

Usage

It writes data to an external text file which can be used in other applications.

Syntax

Write(<filename>,<buffer>)
Write(<filename>,<buffer>,<n>)
Write(<filename>,<buffer>,<sep$>)
Write(<filename>,<buffer>,CRLF)
or
ret=Write(<filename>,<buffer>)
ret=Write(<filename>,<buffer>,<n>)
ret=Write(<filename>,<buffer>,<sep$>)
ret=Write(<filename>,<buffer>,CRLF)

Parameters

<filename>, string, name of the file to which <buffer> is written. It's not necessary to create the file first ; if the file does not exist, it is created when the first write is performed. If the file already exists, the write is done after the existing data. If you use Unicode encoding, the file must have been created first using CreateUnicodeFile function before Write can write Unicode strings.

<filename> is a string, either a variable either a constant. Long names are accepted as well as UNC names (such as \\server\c\my directory\my file.txt).

<buffer>: string, it must be a variable. Up to 32K of data can be written with a single Write. <buffer> is added at the end of file <filename>.

The Write is always performed sequentially; it's not possible to change the write pointer (as you can with the Read function).

<n>, integer; only the first n bytes of <buffer> are written in the file. If <buffer> contains less than n characters, it is padded with spaces.

<sep$>, string (variable or constant). First <buffer> is written to the file, then <sep$> is written.

CRLF: keyword (chr$(13)+chr$(10)), which can be used as a separator in order to write to a file one line at a time.

Return value

Ret, numeric return code. When the Write is successful, the function returns 0, otherwise use this return code for Error Handling.

Examples

 

Write(file$,var$)

Write("c:\sample.txt", var$)

Write(file$,var$,80)

Write(file$,var$,n)

Write(file$,var$,CRLF)

Write(file$,var$,"sample")

Example code

For a complete example, see the Read function