Writing to a file with FoxPro
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.
lnFileHandle =
FCREATE
('fred.txt')
FWRITE
(lnFileHandle, 'Hello Mum')
FWRITE
(lnFileHandle, 'This is some text for my file')
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
The FWRITE function 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 Carriage Return character to the file:
lnFileHandle =
FCREATE
('fred.txt')
FWRITE
(lnFileHandle, 'Hello Mum')
FWRITE
(lnFileHandle, Chr(13))
FWRITE
(lnFileHandle, 'This is some text for my file')
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 function is usually more suitable than
FWRITE()
when working with text files.
|