[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Marv

10/4/2011 11:33:00 PM

Why would the following not result in an error condition. I want to
determine if the default printer is on line before I do the actual
printing. When the default printer is a Canon iP2600 it does cause the
product a warning message from Windows, but does not cause a branch to
the tag TrapError in VB. If the default printer is a Brother HL-5370W
printer nothing is generated.

Private Sub TestPrinter

on error goto TrapError
printer.print "": printer.EndDoc
exit sub
TrapEError:
stop
End Sub

10 Answers

JensB

10/4/2011 11:39:00 PM

0

Marv expressed precisely :
> Why would the following not result in an error condition. I want to
> determine if the default printer is on line before I do the actual printing.
> When the default printer is a Canon iP2600 it does cause the product a
> warning message from Windows, but does not cause a branch to the tag
> TrapError in VB. If the default printer is a Brother HL-5370W printer
> nothing is generated.
>
> Private Sub TestPrinter
>
> on error goto TrapError
> printer.print "": printer.EndDoc
> exit sub
> TrapEError:
> stop
> End Sub

Because there is no error in VB. VB has successfully sent the document
to the printer queue. It has done what it was asked to do. What
happens after that is not its problem.

--
Michael Cole


Marv

10/4/2011 11:49:00 PM

0

On 10/4/2011 7:38 PM, Michael Cole wrote:
> Marv expressed precisely :
>> Why would the following not result in an error condition. I want to
>> determine if the default printer is on line before I do the actual
>> printing. When the default printer is a Canon iP2600 it does cause the
>> product a warning message from Windows, but does not cause a branch to
>> the tag TrapError in VB. If the default printer is a Brother HL-5370W
>> printer nothing is generated.
>>
>> Private Sub TestPrinter
>>
>> on error goto TrapError
>> printer.print "": printer.EndDoc
>> exit sub
>> TrapEError:
>> stop
>> End Sub
>
> Because there is no error in VB. VB has successfully sent the document
> to the printer queue. It has done what it was asked to do. What happens
> after that is not its problem.
>

OK,I can see the logic in that. Is there a means of determining if the
printer is available in VB?

ralph

10/5/2011 3:52:00 AM

0

On Tue, 04 Oct 2011 19:48:57 -0400, Marv <NoBdy@columbus.rr.com>
wrote:

>On 10/4/2011 7:38 PM, Michael Cole wrote:
>> Marv expressed precisely :
>>> Why would the following not result in an error condition. I want to
>>> determine if the default printer is on line before I do the actual
>>> printing. When the default printer is a Canon iP2600 it does cause the
>>> product a warning message from Windows, but does not cause a branch to
>>> the tag TrapError in VB. If the default printer is a Brother HL-5370W
>>> printer nothing is generated.
>>>
>>> Private Sub TestPrinter
>>>
>>> on error goto TrapError
>>> printer.print "": printer.EndDoc
>>> exit sub
>>> TrapEError:
>>> stop
>>> End Sub
>>
>> Because there is no error in VB. VB has successfully sent the document
>> to the printer queue. It has done what it was asked to do. What happens
>> after that is not its problem.
>>
>
>OK,I can see the logic in that. Is there a means of determining if the
>printer is available in VB?

There can be a few nuances (surprises? <g>) with the "default
printer", several ways to go about finding it and what other printers
might be available. (I'll let others fill in the details. <g>)

However, in general the current default printer is the one the Printer
object will "default" to. ..

Dim sTemp As String
With Printer
Debug.Print "Current (Default) Printer is " & .DeviceName
Debug.Print "Current Port is " & .Port
End With

Here is another way via the Printers collection ...
Dim vInfo
Dim iDefaultIndex As Integer
For Each vInfo In Printers
' Add printer name and port to a ListBox
ListBox1.AddItem vInfo.DeviceName & " Port " & vInfo.Port
' Check for default printer
if vInfo.DeviceName=Printer.DeviceName Then
iDefaultIndex = ListBox1.NewIndex
Next
' highlight the default
lstPrinter.ListIndex = iDefaultIndex

You can also read the registery.

The above usually works, but trouble can be brewing if the user is
using other utilities, if your application is fiddling with the
Printer object in more than one location, or if using the Common
Dialog at the same time... etc, etc.

-ralph

David Youngblood

10/5/2011 11:54:00 AM

0


"Marv" <NoBdy@columbus.rr.com> wrote in message
news:j6g61a$6ti$1@speranza.aioe.org...
> On 10/4/2011 7:38 PM, Michael Cole wrote:
>> Marv expressed precisely :
>>> Why would the following not result in an error condition. I want to
>>> determine if the default printer is on line before I do the actual
>>> printing. When the default printer is a Canon iP2600 it does cause the
>>> product a warning message from Windows, but does not cause a branch to
>>> the tag TrapError in VB. If the default printer is a Brother HL-5370W
>>> printer nothing is generated.
>>>
>>> Private Sub TestPrinter
>>>
>>> on error goto TrapError
>>> printer.print "": printer.EndDoc
>>> exit sub
>>> TrapEError:
>>> stop
>>> End Sub
>>
>> Because there is no error in VB. VB has successfully sent the document
>> to the printer queue. It has done what it was asked to do. What happens
>> after that is not its problem.
>>
>
> OK,I can see the logic in that. Is there a means of determining if the
> printer is available in VB?

The short answer is no. Printer status is only available *after* a print job
has started.
See mskb160129:"How to get the status of a printer and a print job"
http://support.microsoft.com...

David


David Benson

10/5/2011 2:54:00 PM

0

David Youngblood was thinking very hard :
> "Marv" <NoBdy@columbus.rr.com> wrote in message
> news:j6g61a$6ti$1@speranza.aioe.org...
>> On 10/4/2011 7:38 PM, Michael Cole wrote:
>>> Marv expressed precisely :
>>>> Why would the following not result in an error condition. I want to
>>>> determine if the default printer is on line before I do the actual
>>>> printing. When the default printer is a Canon iP2600 it does cause the
>>>> product a warning message from Windows, but does not cause a branch to
>>>> the tag TrapError in VB. If the default printer is a Brother HL-5370W
>>>> printer nothing is generated.
>>>>
>>>> Private Sub TestPrinter
>>>>
>>>> on error goto TrapError
>>>> printer.print "": printer.EndDoc
>>>> exit sub
>>>> TrapEError:
>>>> stop
>>>> End Sub
>>>
>>> Because there is no error in VB. VB has successfully sent the document
>>> to the printer queue. It has done what it was asked to do. What happens
>>> after that is not its problem.
>>>
>>
>> OK,I can see the logic in that. Is there a means of determining if the
>> printer is available in VB?
>
> The short answer is no. Printer status is only available *after* a print job
> has started.
> See mskb160129:"How to get the status of a printer and a print job"
> http://support.microsoft.com...

An alternative is to set up a web cam, point it at the printer, and
then use imaging software to check the printer state, but that would be
left as an exercise for the reader - I've never tried to do this
myself...

--

Michael Cole


ralph

10/5/2011 3:56:00 PM

0

On Thu, 06 Oct 2011 01:54:26 +1100, Michael Cole <noone@invalid.com>
wrote:

>David Youngblood was thinking very hard :
>> "Marv" <NoBdy@columbus.rr.com> wrote in message
>> news:j6g61a$6ti$1@speranza.aioe.org...
>>> On 10/4/2011 7:38 PM, Michael Cole wrote:
>>>> Marv expressed precisely :
>>>>> Why would the following not result in an error condition. I want to
>>>>> determine if the default printer is on line before I do the actual
>>>>> printing. When the default printer is a Canon iP2600 it does cause the
>>>>> product a warning message from Windows, but does not cause a branch to
>>>>> the tag TrapError in VB. If the default printer is a Brother HL-5370W
>>>>> printer nothing is generated.
>>>>>
>>>>> Private Sub TestPrinter
>>>>>
>>>>> on error goto TrapError
>>>>> printer.print "": printer.EndDoc
>>>>> exit sub
>>>>> TrapEError:
>>>>> stop
>>>>> End Sub
>>>>
>>>> Because there is no error in VB. VB has successfully sent the document
>>>> to the printer queue. It has done what it was asked to do. What happens
>>>> after that is not its problem.
>>>>
>>>
>>> OK,I can see the logic in that. Is there a means of determining if the
>>> printer is available in VB?
>>
>> The short answer is no. Printer status is only available *after* a print job
>> has started.
>> See mskb160129:"How to get the status of a printer and a print job"
>> http://support.microsoft.com...
>
>An alternative is to set up a web cam, point it at the printer, and
>then use imaging software to check the printer state, but that would be
>left as an exercise for the reader - I've never tried to do this
>myself...

I misunderstood the OP's question, but this post reminded me of a
company I visited a few years ago. They were expanding rapidly and
occupied several non-adjoining floors of an office building plus
several offices in other nearby buildings.

While on the grand tour I noticed people taking pictures with their
cell phones of printer stations. Apparently the administrators had
sent sheets to each of their printers with instructions to anyone who
found them to email/text back with information about the printer and
where it was located - "attaching pictures if possible".

I didn't think of it at the time, but perhaps they were also checking
on the state?

-ralph

Marv

10/5/2011 6:50:00 PM

0

On 10/5/2011 7:54 AM, David Youngblood wrote:
> "Marv"<NoBdy@columbus.rr.com> wrote in message
> news:j6g61a$6ti$1@speranza.aioe.org...
>> On 10/4/2011 7:38 PM, Michael Cole wrote:
>>> Marv expressed precisely :
>>>> Why would the following not result in an error condition. I want to
>>>> determine if the default printer is on line before I do the actual
>>>> printing. When the default printer is a Canon iP2600 it does cause the
>>>> product a warning message from Windows, but does not cause a branch to
>>>> the tag TrapError in VB. If the default printer is a Brother HL-5370W
>>>> printer nothing is generated.
>>>>
>>>> Private Sub TestPrinter
>>>>
>>>> on error goto TrapError
>>>> printer.print "": printer.EndDoc
>>>> exit sub
>>>> TrapEError:
>>>> stop
>>>> End Sub
>>>
>>> Because there is no error in VB. VB has successfully sent the document
>>> to the printer queue. It has done what it was asked to do. What happens
>>> after that is not its problem.
>>>
>>
>> OK,I can see the logic in that. Is there a means of determining if the
>> printer is available in VB?
>
> The short answer is no. Printer status is only available *after* a print job
> has started.
> See mskb160129:"How to get the status of a printer and a print job"
> http://support.microsoft.com...
>
> David
>
>
I looked at that site. Since the program that I was trying to get the
printer status for will only be used by myself and a couple of others it
doesn't appear worth the effort. I'll just display a message box before
the routine that does the printing that they should check the status of
the printer.

Thanks to you and the others for the input.

H-Man

10/5/2011 8:31:00 PM

0

On Tue, 04 Oct 2011 19:33:29 -0400, Marv wrote:

> Why would the following not result in an error condition. I want to
> determine if the default printer is on line before I do the actual
> printing. When the default printer is a Canon iP2600 it does cause the
> product a warning message from Windows, but does not cause a branch to
> the tag TrapError in VB. If the default printer is a Brother HL-5370W
> printer nothing is generated.
>
> Private Sub TestPrinter
>
> on error goto TrapError
> printer.print "": printer.EndDoc
> exit sub
> TrapEError:
> stop
> End Sub

Does OpenPrinter return an error if the printer is off-line?

Private Declare Function OpenPrinter Lib "winspool.drv" Alias
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault
As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As
Long) As Long
Private Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA"
(ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long,
ByVal Level As Long, pJob As Any, ByVal cdBuf As Long, pcbNeeded As Long,
pcReturned As Long) As Long
Private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.a...
'E-Mail: KPDTeam@Allapi.net
Dim hPrinter As Long, lNeeded As Long, lReturned As Long
Dim lJobCount As Long
OpenPrinter Printer.DeviceName, hPrinter, ByVal 0&
EnumJobs hPrinter, 0, 99, 1, ByVal 0&, 0, lNeeded, lReturned
If lNeeded > 0 Then
ReDim byteJobsBuffer(lNeeded - 1) As Byte
EnumJobs hPrinter, 0, 99, 1, byteJobsBuffer(0), lNeeded, lNeeded,
lReturned
If lReturned > 0 Then
lJobCount = lReturned
Else
lJobCount = 0
End If
Else
lJobCount = 0
End If
ClosePrinter hPrinter
MsgBox "Jobs in printer queue: " + CStr(lJobCount), vbInformation
End Sub



--
HK

David Kaye

10/6/2011 11:48:00 PM

0

"David Youngblood" <dwy@flash.net> wrote

> The short answer is no. Printer status is only available *after* a print
> job has started.
> See mskb160129:"How to get the status of a printer and a print job"
> http://support.microsoft.com...

I had this situation come up when designing an appointment reminder system
for a medical center. The idea was to print out a list of successful and
unsuccessful automated phone calls, so that when the clinic opened in the
morning they'd have a list waiting for them. Problem was that sometimes a
worker would turn off the printer or unplug it during the overnight hours.

The good news is that the print job remained in the print queue so that when
the printer was turned on again it would start printing its backlogged jobs.

Short of digging into the API I can't think of any VBish way of testing the
status of a printer.



Mike Scirocco

10/7/2011 2:16:00 AM

0

On 10/6/2011 4:47 PM, David Kaye wrote:
> "David Youngblood"<dwy@flash.net> wrote
>
>> The short answer is no. Printer status is only available *after* a print
>> job has started.
>> See mskb160129:"How to get the status of a printer and a print job"
>> http://support.microsoft.com...
>
> I had this situation come up when designing an appointment reminder system
> for a medical center. The idea was to print out a list of successful and
> unsuccessful automated phone calls, so that when the clinic opened in the
> morning they'd have a list waiting for them. Problem was that sometimes a
> worker would turn off the printer or unplug it during the overnight hours.
>
> The good news is that the print job remained in the print queue so that when
> the printer was turned on again it would start printing its backlogged jobs.
>
> Short of digging into the API I can't think of any VBish way of testing the
> status of a printer.

Would any of these be useful?

Getting the status of the selected printer from Visual Basic
http://www.merrioncomputing.com/Programming/Print...

This potentially can return a lot of different status conditions:
PRINTER_STATUS_READY = &H0
PRINTER_STATUS_PAUSED = &H1
PRINTER_STATUS_ERROR = &H2
PRINTER_STATUS_PENDING_DELETION = &H4
PRINTER_STATUS_PAPER_JAM = &H8
PRINTER_STATUS_PAPER_OUT = &H10
PRINTER_STATUS_MANUAL_FEED = &H20
PRINTER_STATUS_PAPER_PROBLEM = &H40
PRINTER_STATUS_OFFLINE = &H80
PRINTER_STATUS_IO_ACTIVE = &H100
PRINTER_STATUS_BUSY = &H200
PRINTER_STATUS_PRINTING = &H400
PRINTER_STATUS_OUTPUT_BIN_FULL = &H800
PRINTER_STATUS_NOT_AVAILABLE = &H1000
PRINTER_STATUS_WAITING = &H2000
PRINTER_STATUS_PROCESSING = &H4000
PRINTER_STATUS_INITIALIZING = &H8000
PRINTER_STATUS_WARMING_UP = &H10000
PRINTER_STATUS_TONER_LOW = &H20000
PRINTER_STATUS_NO_TONER = &H40000
PRINTER_STATUS_PAGE_PUNT = &H80000
PRINTER_STATUS_USER_INTERVENTION = &H100000
PRINTER_STATUS_OUT_OF_MEMORY = &H200000
PRINTER_STATUS_DOOR_OPEN = &H400000
PRINTER_STATUS_SERVER_UNKNOWN = &H800000
PRINTER_STATUS_POWER_SAVE = &H1000000

Reading the jobs in the print queue from Visual Basic
http://www.merrioncomputing.com/Programming/Pr...

Karl Peterson has some nice code for handling all sorts of printer
tasks, e.g. EnumJobs, GetJob, GetPrinter, OpenPrinter, SetJobThis...
This sample tries to cover all the bases in regard to querying and
controlling printers within Windows. The underlying code is presented
through a user interface that closely mimics that found when you Open
the Printers dialog:
http://vb.mvps.org/sample...

Mike