Write data to a file
Sending lines to a file is quite easy :
In addition of SET PRINTER on | OFF | <xlToggle> command, SET PRINTER, (like many other SET commands,) has a second form distinguished by TO keyword:
SET PRINTER TO [<xcDevice> | <xcFile> [ADDITIVE]]
The on|OFF form of SET PRINTER controls whether the output of console commands is echoed to the printer.
TO <xcDevice> identifies the name of the device where all subsequent printed output will be sent.
TO <xcFile> identifies the name of the output file. ( If a file extension is not specified, (.prn) is assumed.)
By using that last method we can send our lines to a file, instead of sending directly to printer:
SET PRINTER TO Prnfile.txt
SET DEVICE TO PRINTER
SET PRINTER ON
@ 0, 0 SAY "This goes to Prnfile.txt"
? "So will this!"
SET DEVICE TO SCREEN
SET PRINTER OFF
SET PRINTER TO // Close the print file
Note that, though our target is not printer, we have use a SETting printer ON.
We have another method for sending someting to a file may be SET ALTERNATE command:
SET ALTERNATE TO [<xcFile> [ADDITIVE]]
SET ALTERNATE on | OFF | <xlToggle>
SET ALTERNATE is a console command that lets you write the output of console commands to a text file. Commands such as LIST, REPORT FORM, LABEL FORM, and ? that display to the screen without reference to row and column position are console commands. Most of these commands have a TO FILE clause that performs the same function as SET ALTERNATE. Full-screen commands such as @…SAY cannot be echoed to a disk file using SET ALTERNATE. Instead you can use SET PRINTER TO <xcFile> with SET DEVICE TO PRINTER to accomplish this.
SET ALTERNATE has two basic forms. The TO <xcFile> form creates a DOS text file with a default extension of (.txt) and overwrites any other file with the same name. Alternate files are not related to work areas with only one file open at a time. To close an alternate file, use CLOSE ALTERNATE, CLOSE ALL, or SET ALTERNATE TO with no argument.
The on|OFF form controls the writing of console output to the current alternate file. SET ALTERNATE ON begins the echoing of output to the alternate file. SET ALTERNATE OFF suppresses output to the alternate file but does not close it.
This example creates an alternate file and writes the results of the ? command to the file for each record in the Customer database file:
SET ALTERNATE TO Listfile
SET ALTERNATE ON
USE Customer NEW
DO WHILE !EOF()
? Customer->Lastname, Customer->City
SET ALTERNATE OFF
A single difficulty may be making choose the best between possible methods
You can download a working example prg with a sample .dbf from here :