Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I print from qbasic

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I made a graphic by qbasic and BSAVE it.
How do I print (inkjet printer)by Windows98 ?
Thank you.
Francesco
 
I believe that i've seen qbasic programs that use the OPEN COM statement and then use the PRINT # command to send the file to the printer.
 
Your best bet is to install a PostScript printer driver for your printer under Windows and bind it to DOS port LPT1:. Then, output PostScript representing your graphic (PostScript allows for bitmaps too) to LPT1: terminated with a PostScript 'showpage' command. This is the most general solution, and will allow you to print arbitrary vector and bitmap graphics from DOS. It is true, however, that you will have to learn PostScript to do this, and PostScript, I have heard, is quite a complex language. You may not want to put this much effort into a small project.
 
As logiclrd mentioned it would need to be connected to LPT1 and local for QB to have "easy" access (but then again nothing is really that easy). I've located an old program I did years ago and I've left the notes I had made for myself. Just remember to use the library command when accessing the interrups in this example.



' PrntScrn.Bas
'
'Notes: To print graphics you must use GRAPHICS.COM loaded in AutoExec.bat
' don't forget to turn on SetVer.exe (cause the one that is currently
' on this hard drive is expecting DOS V 6.22).
'
' Reminder of syntax for GRAPHICS.COM is: "GRAPHICS.COM {printer name}"
' Where PRINTER NAME is any one of the few printers listed in
' GRAPHICS.PRO (I'm test printing with: "GRAPHICS.COM HPDefault" and
' it works alright but in landscape mode)
'
' Speaking of modes, the following code is for SCREEN 0, 1, & 2 (I've
' tested in SCREEN 12 and it comes out in portriat mode but you'll lose
' some of the screen info.
'
TYPE RegType
AX AS INTEGER
BX AS INTEGER
CX AS INTEGER
DX AS INTEGER
BP AS INTEGER
SI AS INTEGER
DI AS INTEGER
FLAGS AS INTEGER
DS AS INTEGER
ES AS INTEGER
END TYPE
DIM inary AS RegType, Outary AS RegType
CLS
SCREEN 1
PRINT "This goes to the printer"
LINE (1, 1)-(100, 100)
CIRCLE (100, 100), 50
PSET (300, 100), 15
PSET (319, 199), 15
PSET (317, 199), 15
SLEEP 5

'END

CALL interrupt(&H5, inary, Outary) ' Performs screen dump
LPRINT CHR$(12)
SCREEN 0
END


If for some reason you think this is of use to you...the GRAPHICS.com/.pro mentioned comes with DOS Ver 3.3 to Ver 5 (I think).

Good luck, --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
There's a program, I beleive that it's called QBWRITE2.7, it prints, but I've searched the internet and i just can't find a link to it. They use LPRINT. I'm not sure if it will work for graphics though, it is a word processing program.
 
Rathgar, perhaps you should actually read the other posts before posting such comments :) Two of them mentioned LPRINT, and my comment was independent of how one chooses to send information to the printer. It was only the second one which suggested opening a COM port (?!).
 
I'm suprised that we all forgot to ask this: Where is your printer? LPT1, COM1, USB... this will make a difference.
 
I recently bought an HP Pavilion Home PC with a package that included an HP 656c printer. I have used QBASIC for our household finance programmes plus a number of other tasks for years, and have always been able to print to my printer used LPRINT, or opening the printer as a "file" device, and printing to it that way. However, this HP 656c printer uses printer 'port' USB001, which is described as a 'virtual printer port for USB'. The question is how do I get QBASIC to print to the HP 656c printer through this port? When I try using LPRINT, my computer hangs up and sits idle for several minutes.
I have looked at the QBASIC code and found LPT1 in plain ASCII embedded twice in the code, but if I change LPT1 to USB001, QBASIC doesn't work anymore. I think this is because USB001 is 6 characters, while LPT1 is only 3. I know of Machine Language, but am NOT familiar enough with it to work in it. Any help anyone can give would be appreciated.
 
Machine language will not help with this. The problem has nothing to do with the length of the character device -- USB001 is actually a virtual port name, and not an actual character device. However, if you are using Windows NT 4, 2000 or XP, you can still map the printer to a DOS port number. Here's how:

For this example, I will assume that your computer is called "MYCOMP" and you share your printer as "MYPRINTER". I also assume that you want the printer to be on port LPT1:. Ports LPT2: and LPT3: are also valid. Change all of these to the correct values in the 'NET USE' statement below.

First, go to the printers control panel and share the printer, as if for use over the network.

Then, go to a command prompt and issue the following command:
[tt]
NET USE LPT1: \\MYCOMP\MYPRINTER
[/tt]
Unfortunately, this does not work under Windows 9x, because it checks to make sure that you aren't connecting to a local share before proceeding. However, if the printer is connected to a different computer than the one that wishes to print from DOS, this technique can also be used for Windows 9x.

The fundamental problem with writing directly to the printer is that USB printers do not have onboard fonts -- that is, they can only take graphical information. Windows prints text by converting it to graphics first. This means that to use a printer like this from DOS, you must first pass the text through the Windows printer driver.
 
Ok, since it is on a USB port, you can't print out of it yet. Someone else asked how to reach the USB and as of yet, it doesn't look like anybody know the address.
 
qbasicking, pay attention! I just stated that even if you KNEW the address, you wouldn't be able to print directly. It MUST go through a print processor, which converts the text into graphics. That is, unless you were planning on writing your own font rasterization and spooling the voluminous graphical data that it would produce to the printer while at the same time maintaining a responsive user interface.

In any event, if you were to talk to the USB controller directly, its responses would be caught by the Windows driver. This would be undesirable, to say the least. There's a reason why all decent operating systems use a driver system: talking directly to the hardware is not in fashion any more, because now we can run more than one program at once, and if both programs talk directly to the same hardware, crazy things will happen. That's why only one program, the driver, is allowed to talk directly to the hardware.

There will probably never be a way to access the USB ports through QuickBASIC, and even if someone were to create one, it would only be usable in pure DOS, and not in a DOS box under any version of Windows. However, if you want to code this, I'm sure a web search would provide you with the relevant protocol information, including, believe it or not, the I/O port number; it is all standardized.
 
To ARTSQB:

if you have the original code then you can try this...(it's really cheezy but it'll work to some degree)...

rewrite the output to a TXT file instead of LPTx.

Put in something like a 5 second SLEEP (similar to a "poor man's" DOEvent in VB allowing the system some time to write from the cache to HD).

After the SLEEP command, add SHELL "NOTEPAD /P {yourfilenamehere.txt}".

You may endup with headers/footers on the printout but it shouldn't be too bad. I had a Win NT3 system that I removed the headers & footers in the registry so that my (formated) TXTs came out properly.

Otherwise, you may want to try the above code I posted and test it's feasibility on your system.

Good Luck, --MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top