|
-
Jan 7th, 2009, 10:22 PM
#1
Thread Starter
Hyperactive Member
printer!
how can i check if the printer is Turn On?
im using visual basic 6.0
-
Jan 8th, 2009, 12:36 AM
#2
Re: printer!
 Originally Posted by rothj0hn
how can i check if the printer is Turn On?
im using visual basic 6.0
If an error is returned when attempting to access a printer that is off or unavailable, you could then use that error code in an error handler to generate a message. Just a thought....
Code:
If Err.Number = ErrNum Then 'where ErrNum is the error code.
Err.Clear
MsgBox "Unable to access printer. Make sure it's on"
End If
Last edited by CDRIVE; Jan 8th, 2009 at 12:38 AM.
Reason: Indent code
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jan 8th, 2009, 02:22 AM
#3
Thread Starter
Hyperactive Member
Re: printer!
but in some cases if printer is tun off it goes to the printer queue.. i mean the document to be printed.. im using MS Word..
-
Jan 8th, 2009, 09:40 AM
#4
Re: printer!
Are you printing to a local printer or a network printer?
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jan 8th, 2009, 03:37 PM
#5
Re: printer!
 Originally Posted by rothj0hn
but in some cases if printer is tun off it goes to the printer queue.. i mean the document to be printed.. im using MS Word..
Well it's going to go to the printer queue whether the printer is on or off. It will also go to the printer queue if you're printing over a network.
This code will check the Printer Queue once every second. If no jobs are pending the Label returns 0. If jobs are pending it will return the job count pending. If it's only one job then it will return 1. If i > 20 then a MsgBox will tell you to check the printer. You can build and refine this code as you like.
Code:
Option Explicit
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()
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Static i As Integer
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
i = i + 1
Else
lJobCount = 0
i = 0
End If
Else
lJobCount = 0
End If
ClosePrinter hPrinter
Label1.Caption = "Jobs in printer queue: " & CStr(lJobCount)
If i > 20 And lJobCount <> 0 Then
MsgBox "Time out. Check to see if printer in online"
i = 0
End If
Debug.Print i
End Sub
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Jan 8th, 2009, 09:46 PM
#6
Thread Starter
Hyperactive Member
Last edited by rothj0hn; Feb 15th, 2011 at 01:35 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|