Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Get Printer Status

I'm converting diagnostics software for dot matrix and line printers from QBASIC to VB6.

The software sends a lot of single line Esc and Chr$ commands to the printers, for example; to change and test emulations and various attributes and functions and to drive individual print head wires. This doesn't work properly in VB6 using printer.print. I don't want to waste time and a lot of paper just to send a single chr(7) to make the printer beep, do a line feed, carriage return, or whatever. So I'm outputting these codes from VB6 to the printer by opening printer.port for output as #1, and then print #1, chr$(27); chr$(x); etc...

This all works fine unless there is a problem with the printer.

In QBASIC I can monitor the printer status using error trapping to detect offline, paper out, and other printer error conditions.

How can I detect these error conditions in VB6? When I open printer.port and write data to it, if the printer is not ready or if the printer runs out paper during the process, etc, then the Public Sub outputting to printer.port never ends. It doesn't detect any error and the program hangs, waiting forever for the Sub to complete - or for me to Ctrl-Alt-Del to kill the whole thing!

Is there some way to verify that the printer is online and ready first, before
it starts trying to print to printer.port? And also to detect if the printer goes offline, runs out of paper, or whatever, while the Sub is printing to it, so that it can generate a message and then Exit the Sub if there is a problem?
[1602 byte] By [Danamo] at [2007-11-11 8:34:03]