Writing to the file


The FWRITE(<filehandle>,<characters>) function writes the characters specified to the file associated with this filehandle. It overwrites anything that is in this file already.

*-- Create a new file ...
lnFileHandle = FCREATE ('fred.txt')
*-- ... write some text into the file ...
FWRITE (lnFileHandle, 'Hello Mum')
FWRITE (lnFileHandle, 'This is some text for my file') *-- ... and close it.
FCLOSE (lnFileHandle)

Although this example seems to be writing two lines of text to the file, all it will produce is:

Hello MumThis is some text for my file

FWRITE will only write the characters we ask it to write and to get two separate lines of output we would need to explicitly send a CarriageReturn to the file:

*-- Create a new file ...
lnFileHandle = FCREATE ('fred.txt')
*-- ... write some text into the file ...
FWRITE (lnFileHandle, 'Hello Mum')
FWRITE (lnFileHandle, Chr(13))
FWRITE (lnFileHandle, 'This is some text for my file') *-- ... and close it.
FCLOSE (lnFileHandle)

Even within the PC world, different text editors require different combinations of CarriageReturn and LineFeed.

Another low level file function, FPUTS() will write a string of bytes to the file followed by a CarriageReturn and LineFeed. This is usually more suitable for working with text files.


Other low level topics

Low level overview | FCREATE() | FOPEN() | FCLOSE() | FREAD() |


Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map