how can i check if the printer is Turn On?
im using visual basic 6.0
Printable View
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....Quote:
Originally Posted by rothj0hn
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
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..
Are you printing to a local printer or a network printer?
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.Quote:
Originally Posted by rothj0hn
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
ok thanks..
________
Herbal Vaporizer Forum