Q-Basic Question (printing)

A little while ago, after asking you for advice, I received a lot of excellent suggestions about how I might use my XP-based system to do a bit of very simple programming (e.g. stuff like finding the divisiors of a number). Link to my earlier thread.

After a bit of trial and error I wound up using QBasic - it seemed to be closest to what I had been looking for. Only later, did I realize that printing a hard copy of my programs’ output was not straightforward. I then searched around various QBasic FAQs and even posted my question on a QBasic forum. Bottom line is that, apparently, getting a hard copy on paper of your QBasic program’s output is a non-trivial matter.

Can anyone explain to me in a simple way how to print a hard copy of a QBasic program’s output? BY simple, I mean without having to resort to using “shells”, “printing to Notepad”, etc.

By the way, I’m using QuickBasic (no version specified, but it came on my Windows95 system disk, and was modified on May 1, 1997). And, my printer uses a USB connection (i.e. not a parallel port).

Thanks!

If I’m not mistaken, you’d use the LPRINT command to send output to the printer. Now, I’m not sure if this will work for a USB printer. Hopefully, Windows will handle the interface, otherwise, I’m not sure what you can do.

Thanks, but that doesn’t seem to work either.

Yeah, I was afraid of that. Someone must have already conquered this problem; I’ll see what I can dig up.

Share your printer (right click on printer in the Printers and Faxes window and choose sharing). Once you have a share name run the following from DOS to redirect it:

NET USE LPT1: \your_computername_here\your_shared_printername_here /Persistent:YES

So, if your computer is named KarlsBox and you named your printer share KarlsUSBPrinter, the command would be:

NET USE LPT1: \KarlsBox\KarlsUSBPrinter /Persistent:YES

If that works for you, you should be able to send your output to LPT1: which should work fine in any DOS app, including Q-Basic.

DMC’s technique ought to work. But there is probably (at least) one more issue to solve.

When QBASIC was designed, dot matrix or other impact printers were typical. As a result, as each byte was sent from the program, it ended up directly on the paper. Modern printers are page printers & won’t actually put anything on paper until the page is somehow marked complete. Absent the complete mark, your output just sits in the printer’s RAM.

Windows (from 3.1 on) also imposes a spooler in the middle. So something has to both mark the page complete for the printer, and tell the spooler the print job is complete.

Try LPRINT CHR(12) at the end of your program to complete the page.

Telling the spooler you’re done may be harder. Perhaps it’ll only close the spoolfile & print when you quit QBASIC. Or the spooler may timeout after, say, 30 seconds with no ouput from the program & auto-close the spoolfile.

If neither of those work, you may try something like this. Pardon my crappy guess at correct QBASIC syntax, I haven’t thought about this is 15 years.

10 OPEN “LPT1:”, Output as #1
20 WRITELN #1,“Karl says Hello World!”
30 WRITELN #1, CHR(12)
40 CLOSE #1
Good luck.

if you want all the output from your program to be printed, you can go to the DOS command shell and type something like

QBASIC/RUN progname >prn

or

QBASIC/RUN progname >filename.txt

to send the output to a file which you can then edit and/or print.

If you want the program itself to send some or all of its output either directly to the printer, or to a file which you can then print, instead of to the screen, include the line

OPEN “filename.txt” FOR OUTPUT AS #1

or

OPEN “PRN” FOR OUTPUT AS #1

near the beginning of your program. Then go through and change every PRINT statement to PRINT #1,