Printing to a file
Printing to a file
(OP)
I'm modifying an old FoxPro for DOS program. Currently, it will do some processing and print out a nice little report. In an effort to move toward a paperless office (or, at least kill less that half a forest each month), I've been asked to make the report print to a file which will be stored on the network.
The question is, how? I tried a
set device to file report.txt
statement, but it doesn't appear to have worked correctly. I end up with a file that has a few records, none of the headings, and a whole lot of blank lines. I also noticed that a lot of stuff that looked like the report headers was being printed to the screen. What's going on?
The program currently prints using the following type of code:
set device to printer
set print on
@ a,b SAY whatever
It also uses
? whatever
statements to print the headers. This is done in a separate program file.
Does anyone have any ideas? Is there anything I should look for?
The question is, how? I tried a
set device to file report.txt
statement, but it doesn't appear to have worked correctly. I end up with a file that has a few records, none of the headings, and a whole lot of blank lines. I also noticed that a lot of stuff that looked like the report headers was being printed to the screen. What's going on?
The program currently prints using the following type of code:
set device to printer
set print on
@ a,b SAY whatever
It also uses
? whatever
statements to print the headers. This is done in a separate program file.
Does anyone have any ideas? Is there anything I should look for?
RE: Printing to a file
SET DEVICE TO PRINT
and
SET PRINT TO FILE whatever.TXT [ADDITIVE] is optional
When it's done, use
SET PRINT TO
and
SET DEVICE TO SCREEN
Dave S.
RE: Printing to a file
Thanks for the response. I tried your suggestion and, as a result, I'm making progress. I'm now getting all the records in the report. On the down side, I'm still getting the report headers printing to the screen.
The body of my report is generated by a file called snowbody.prg (it's for tracking county snow removal costs). This part is working now. The report headers are generated by snowhead.prg. In snowbody.prg I have now set
set device to print
set print to file report.txt
I tried setting something similar in snowhead.prg, but it just messed things up. How can I get the headings to also be written to the file?
Also, just so I'm sure, when I'm done I do
set print to screen
set device to screen
right? I just wanted to be sure that's what you meant.
RE: Printing to a file
Before your the command:
SET DEVICE TO PRINT
Issue the command
SET CONSOLE OFF
then, instead of set device to screen,
issue:
SET CONSOLE ON
Thanks,

-Scott
Please let me know if this has helped!
RE: Printing to a file
SET CONSOLE OFF
SET PRINTER TO FILE report.txt
SET DEVICE TO PRINTER
SET PRINTER ON
?'? asdfasdfasdfasdf'
?'? asdfasdfasdfasdf'
?'? asdfasdfasdfasdf'
?'? asdfasdfasdfasdf'
@ 1, 1 SAY '@ asdfasdfasdfasdf'
@ 2, 1 SAY '@ asdfasdfasdfasdf'
@ 3, 1 SAY '@ asdfasdfasdfasdf'
@ 4, 1 SAY '@ asdfasdfasdfasdf'
SET PRINTER OFF
SET PRINTER TO
SET CONSOLE ON
SET DEVICE TO SCREEN
This produces the following output in report.txt:
? asdfasdfasdfasdf
? asdfasdfasdfasdf
? asdfasdfasdfasdf
? asdfasdfasdfasdf FormFeed
@ asdfasdfasdfasdf
@ asdfasdfasdfasdf
@ asdfasdfasdfasdf
@ asdfasdfasdfasdf
Note I have put a formfeed in because since the print row is incremented for each '?', so '@ 1, 1' will be prior to the current row thereby causing an eject.
Dave S.
RE: Printing to a file
One last question, Dave. At the end of the report, I put
SET PRINTER TO
as in your post. On that line, it gives me the following error:
This device does not exist on the network. reading device
Abort, Retry, Fail?
How can I fix this? Is there some keyword, e.g. EMPTY, NULL, or NOTHING, that I can set it to rather than just blank space?
RE: Printing to a file
SET PRINTER TO with nothing after it sets it back to the default printer, but maybe FPD don't quite know how to interpret what it is at that point. Not sure. You might try just using SET PRINTER TO lpt1: or some other generic port, or even to the actual printer name associated with it just to release the text file as the print job.
Dave S.
RE: Printing to a file
I seem to have messed something up. I need to be able to print to BOTH a file and the printer. The file part is working fine now. The printer part is not. (At least I think it's not, since I don't have a local printer to test it with and it doesn't recognize the network printer.) I tried to use the same program file to do both using if statements. Here's the code:
set color to w/b,gr+/n,b
set talk off
use snowtemp
store 12 to linecnt
set fixed on
set escape on
if usefile = 0
set device to printer
set print on
else
* NEW CODE BEGINS
set console off
set printer to file report.txt
set device to printer
set printer on
* NEW CODE ENDS
endif
* Do the report building
if usefile = 0
set device to screen
@ 0,0 say chr(27)+"E"
set print off
else
* NEW CODE BEGINS
set printer off
set printer to
set console on
set device to screen
* NEW CODE ENDS
endif
I once again seem to get the report headers being dumped to the screen, but this time when I try to print. By all rights, I should be getting a printer not ready error (I did before). I checked the header printing program, and it's unchanged from the original code. I tried exiting FoxPro to reset the environment (I thought maybe something was still set to output to the console).
What's wrong?
RE: Printing to a file
Dave S.
RE: Printing to a file
RE: Printing to a file
SET COLOR TO w/b,gr+/N,b
SET TALK OFF
USE snowtemp
STORE 12 TO linecnt
SET FIXED ON
SET ESCAPE ON
SET CONSOLE OFF
IF usefile = 0
SET PRINTER TO whatever &&... either network printer name or lpt1: etc.,
ELSE
SET PRINTER TO FILE REPORT.txt
ENDIF
SET DEVICE TO PRINTER
SET PRINTER ON
* Do the report building
SET PRINTER OFF
SET PRINTER TO lpt1
SET CONSOLE ON
SET DEVICE TO SCREEN
Dave S.
RE: Printing to a file
ergo
!type report.txt>prn
only works if you left your printer formatting in the report
(i use this to preview )
!edit report.txt
alt-f p
RE: Printing to a file
I figured out the last question, and now I feel kind of dumb. I thought the code I had would work, and, in fact, it did work. I had a user test it on her machine this morning, and it printed out perfectly. After I deleted the FOXUSER.* files from my working directory, I started getting the "no printer" error messages I had before. Apparently it was just some printer setting that got saved when I didn't want it to. I'll have to do some reading on that.
Anyway, thanks again!