Solved

trapping printer errors

Posted on 1998-12-07
7
281 Views
Last Modified: 2013-12-25
I am able to print the files in visual basic 5.0, but my problem is to trap the printer error and pass it to a log file.

Here I am facing problem in capturing the printer error ,if suppose printer is offline,no ink,out of paper,paper jam etc..

Please help me to solve this.
0
Comment
Question by:bk_madhu
  • 5
  • 2
7 Comments
 

Author Comment

by:bk_madhu
ID: 1488767
Edited text of question
0
 
LVL 3

Accepted Solution

by:
jjbyers earned 200 total points
ID: 1488768
Go under Index in VB Help and look up Trappable Errors

There you will see the following error numbers

Num    Type
482      Printer Error
483      Printer driver does not support specified property
484      Problem getting printer information from the system. Make sure the printer is set up correctly

To trap these errors use the following code where ever you send info to the printer

function PrintOut() as boolean

  ON ERROR GOTO Err_Handler 'This line goes at top of method

  'Method code goes here

  PrintOut=true
  Exit Function

Err_Handler:  'This goes at bottom
  select case err.number
    case 482, 483, 484
       msgbox "Printer Error of " & err.description & " " & err.number
    case else
       msgbox "Different error of " & err.description & " " & err.number
  end select
  PrintOut=false
END FUNCTION

Hope this helps.
0
 

Author Comment

by:bk_madhu
ID: 1488769
hi jjbyers !

I recieved your answer to my question. I used the code you had sent in my program,but my problem is not solved yet. program is not taking 482,483,484 errors,instead it is going to else case statement.
I am using below code to print the pdf file.

 comm = "C:\Acrobat3\Reader\AcroRd32.exe /t C:\retr\" & MyName & " qcine KHQCNE.drv                                                                                                                                     LPT1 "
      Call Shell(comm, 1)
                     
       here I am not using print object , instead  Iam invoking shell command to run the acrobat reader and to print the pdf file. In this method I am not able to get the printer error.


Should I use print object ?     If I have to use, how to run acrobat reader (AcroRd32.exe) and print the pdf file ?

Please help me to solve this problem.

bye
Madhu
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:bk_madhu
ID: 1488770
hi jjbyers !

I recieved your answer to my question. I used the code you had sent in my program,but my problem is not solved yet. program is not taking 482,483,484 errors,instead it is going to else case statement.
I am using below code to print the pdf file.

 comm = "C:\Acrobat3\Reader\AcroRd32.exe /t C:\retr\" & MyName & " qcine KHQCNE.drv                                                                                                                                     LPT1 "
      Call Shell(comm, 1)
                     
       here I am not using print object , instead  Iam invoking shell command to run the acrobat reader and to print the pdf file. In this method I am not able to get the printer error.


Should I use print object ?     If I have to use, how to run acrobat reader (AcroRd32.exe) and print the pdf file ?

Please help me to solve this problem.

bye
Madhu
0
 
LVL 3

Expert Comment

by:jjbyers
ID: 1488771
The only way to trap print errors from another program would be to use a Windows API call for your program to get all Windows messages first and log them and then pass them along to whichever program.

That's alot of work, and if I remember requires a C based DLL.

Any reason you need to trap another programs error?
0
 

Author Comment

by:bk_madhu
ID: 1488772
hi jjbyers !

I am not satisfied  by your answer. There is only one program which is printing PDF files and is suppose to trap the printer errors ,but wich is not doing.
Here is the entire source code of mine, if possible please tell me where I have gone wrong.

 In this program, files are retrieved from the remote server using cFTP class and are stored in the local system (C:\retr) .Since all the files are  PDF files, adobe acrobat reader  (AcroRd32.exe)is activated and then files are sent for printing. I have to use acrobat reader exe file otherwise , while printing it takes all the pdf header files along with the file content. Till here it is suceesfully doing fine.  Now I think you know about my problem i.e., to trap the printer error. I am using  Qnix color inkjet Printer.

If Printer is offline , the program should return an error message. Here it is not recognising printer errors 482,483,484, instead it is taking different error 0 .

Please help me to solve this problem or suggest anyone who has experience in printing files and trapping errors automatically in VB.

bye
madhu
 

Type Record
    ID          As Integer
    buf         As String * 60
End Type


Option Explicit

Private Sub cmdDownload_Click()
        Dim ftp1            As New cFTP
        Dim sDir            As String
        Dim destcounter     As String
        Dim counter         As String
        Dim counter1        As String
        Dim reffile         As String
        Dim reffile1        As String
        Dim filename        As String
        Dim filename1       As String
        Dim filename2       As String
        Dim temp            As String
        Dim buf             As String
        Dim recnum          As Integer
        Dim myrecord        As Record
        Dim myrecord1       As Record
        Dim found1, found2
        Dim found3, found4, founda, foundb
        Dim message         As String
        Dim message1        As String
        Dim content         As String
        Dim Address         As String
        Dim lpos            As Long
        Dim lposn           As Long
        Dim mydate
        Dim Textline        As Integer
        Dim MyPath, MyName
        Dim BeginPage, EndPage, NumCopies, i, j
        Dim lstr As String * 200
        Dim comm            As String
        Dim digit
        Dim File            As String
        Dim Msg
        Dim i1               As Integer
        Dim Vall                As String
        Dim Val2                As String
        'Dim Number          As Integer

        ftp1.ServerName = "www.ipo.com"
        ftp1.Username = "ipo.com"
        ftp1.Password = "net2mail"
       
        sDir = "/home/www/ipo.com"
       
        Open "C:\temp\destcounter.txt" For Input Access Read As #1
        If Not EOF(1) Then
            Line Input #1, destcounter
        End If
        Close #1
        destcounter = Trim$(destcounter)
        counter = Val(destcounter)
        recnum = Val(Right(destcounter, 5))
        reffile = Left(destcounter, 8) & ".lst"
       
        ftp1.SourceFilename = sDir & "/" & reffile
        ftp1.DestinationFilename = "c:\daysreffile\" & reffile
        temp = ftp1.DestinationFilename
        ftp1.OneStepDownload
       
        recnum = 1
        Open temp For Random Access Read As #1 Len = Len(myrecord)
        Do
            If (Not EOF(1)) Then
                Seek #1, recnum
                Get #1, , myrecord

                    If (Trim$(myrecord.buf) <> "") Then
                        found1 = InStr(1, myrecord.buf, ";", 1)
                        found2 = InStr(found1 + 1, myrecord.buf, ";", 1)
                        Mid(myrecord.buf, found1, 1) = "|"
                   
                        reffile1 = Trim$(Mid(myrecord.buf, found1 + 1, found2 - (found1 + 1)))

                       
                    End If
                    ftp1.SourceFilename = sDir & "/" & reffile1
                    lpos = FindLastOccurrence(reffile, "/")
                    If lpos <> 0 Then
                        ftp1.DestinationFilename = "C:\retr\" & Trim$(Mid(reffile1, lpos + 1))
                    Else
                        ftp1.DestinationFilename = "C:\retr\" & reffile1
                    End If
                    ftp1.OneStepDownload
                                   
                   
            End If
            recnum = recnum + 1
            counter = counter + 1
            Loop While (Not EOF(1)) And (Trim$(myrecord.buf) <> "")
            counter1 = counter - 1
            recnum = recnum - 1
            Close #1
           
           
            Open "C:\temp\destcounter.txt" For Binary Access Write As #1 Len = Len(myrecord)
                If Not EOF(1) Then
                    Put #1, , counter1
                End If
            Close #1
           
            destcounter = "1998100500001"
            recnum = 1
            MyPath = "C:\retr\"
         
            If (GetAttr(MyPath) = vbDirectory) Then
                MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
                Do While MyName <> ""   ' Start the loop.
                    If MyName <> "." And MyName <> ".." Then
                        If (GetAttr(MyPath & MyName) And vbDirectory) <> vbDirectory Then
                            filename1 = "C:\retr\" & MyName
                            digit = Right(filename1, 4)
                             
                                                       
                         
                       comm = "C:\Acrobat3\Reader\AcroRd32.exe /t C:\retr\" & MyName & " qcine                                                                                                                KHQCNE.drv  LPT1 "
                         
                       
                           
                      Call Shell(comm, 1)
                        MsgBox (Printer.DriverName)
                       
                   
                       
                       
                   '' Function PrintOut() As Boolean

                     On Error GoTo Err_Handler 'This line goes at top of method

                        'Method code goes here

                        '' PrintOut = True
                        '' Exit Function

Err_Handler:      'This goes at bottom
                Select Case Err.Number
                Case 482, 483, 484
                    MsgBox "Printer Error of " & Err.Description & " " & Err.Number
                Case Else
                MsgBox "Different error of " & Err.Description & " " & Err.Number
                End Select
     '' PrintOut = False
   '' End Function
                     

              Printer.EndDoc
      If Err.Number = 0 Then
           Msg = "Error # " & Str(Err.Number) '& " was generated by " _
           & Err.Source & Chr(13) & Err.Description
            'MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
     
           
                           filename2 = Trim$(Mid(filename1, 9))
                           Address = " Cubbon road"
                           
                         content = recnum & " " & "|" & " " & destcounter & " " & ";" & " " & filename2 & " "                                                           & ";" & " " & Msg & " " & ";" & " " & Address
                          destcounter = destcounter + 1
                         Open "C:\Temp\log.txt" For Append Access Write As #1 Len = Len(myrecord)
                                   Write #1, , content
                         
                          Close #1
           
                               
                                   End If
                       End If
                       End If
                       recnum = recnum + 1
 
                    MyName = Dir
                Loop
            End If


End Sub

Public Sub Main()
    Call cmdDownload_Click
End Sub


0
 

Author Comment

by:bk_madhu
ID: 1488773
hi jjbyers !

I am not satisfied  by your answer. There is only one program which is printing PDF files and is suppose to trap the printer errors ,but wich is not doing.
Here is the entire source code of mine, if possible please tell me where I have gone wrong.

 In this program, files are retrieved from the remote server using cFTP class and are stored in the local system (C:\retr) .Since all the files are  PDF files, adobe acrobat reader  (AcroRd32.exe)is activated and then files are sent for printing. I have to use acrobat reader exe file otherwise , while printing it takes all the pdf header files along with the file content. Till here it is suceesfully doing fine.  Now I think you know about my problem i.e., to trap the printer error. I am using  Qnix color inkjet Printer.

If Printer is offline or out of paper or no ink , the program should return an error message. Here it is not recognising printer errors 482,483,484, instead it is taking different error 0 .

Please help me to solve this problem or suggest anyone who has experience in printing files and trapping errors automatically in VB.

bye
madhu
 

Type Record
    ID          As Integer
    buf         As String * 60
End Type


Option Explicit

Private Sub cmdDownload_Click()
        Dim ftp1            As New cFTP
        Dim sDir            As String
        Dim destcounter     As String
        Dim counter         As String
        Dim counter1        As String
        Dim reffile         As String
        Dim reffile1        As String
        Dim filename        As String
        Dim filename1       As String
        Dim filename2       As String
        Dim temp            As String
        Dim buf             As String
        Dim recnum          As Integer
        Dim myrecord        As Record
        Dim myrecord1       As Record
        Dim found1, found2
        Dim found3, found4, founda, foundb
        Dim message         As String
        Dim message1        As String
        Dim content         As String
        Dim Address         As String
        Dim lpos            As Long
        Dim lposn           As Long
        Dim mydate
        Dim Textline        As Integer
        Dim MyPath, MyName
        Dim BeginPage, EndPage, NumCopies, i, j
        Dim lstr As String * 200
        Dim comm            As String
        Dim digit
        Dim File            As String
        Dim Msg
        Dim i1               As Integer
        Dim Vall                As String
        Dim Val2                As String
        'Dim Number          As Integer

        ftp1.ServerName = "www.ipo.com"
        ftp1.Username = "ipo.com"
        ftp1.Password = "net2mail"
       
        sDir = "/home/www/ipo.com"
       
        Open "C:\temp\destcounter.txt" For Input Access Read As #1
        If Not EOF(1) Then
            Line Input #1, destcounter
        End If
        Close #1
        destcounter = Trim$(destcounter)
        counter = Val(destcounter)
        recnum = Val(Right(destcounter, 5))
        reffile = Left(destcounter, 8) & ".lst"
       
        ftp1.SourceFilename = sDir & "/" & reffile
        ftp1.DestinationFilename = "c:\daysreffile\" & reffile
        temp = ftp1.DestinationFilename
        ftp1.OneStepDownload
       
        recnum = 1
        Open temp For Random Access Read As #1 Len = Len(myrecord)
        Do
            If (Not EOF(1)) Then
                Seek #1, recnum
                Get #1, , myrecord

                    If (Trim$(myrecord.buf) <> "") Then
                        found1 = InStr(1, myrecord.buf, ";", 1)
                        found2 = InStr(found1 + 1, myrecord.buf, ";", 1)
                        Mid(myrecord.buf, found1, 1) = "|"
                   
                        reffile1 = Trim$(Mid(myrecord.buf, found1 + 1, found2 - (found1 + 1)))

                       
                    End If
                    ftp1.SourceFilename = sDir & "/" & reffile1
                    lpos = FindLastOccurrence(reffile, "/")
                    If lpos <> 0 Then
                        ftp1.DestinationFilename = "C:\retr\" & Trim$(Mid(reffile1, lpos + 1))
                    Else
                        ftp1.DestinationFilename = "C:\retr\" & reffile1
                    End If
                    ftp1.OneStepDownload
                                   
                   
            End If
            recnum = recnum + 1
            counter = counter + 1
            Loop While (Not EOF(1)) And (Trim$(myrecord.buf) <> "")
            counter1 = counter - 1
            recnum = recnum - 1
            Close #1
           
           
            Open "C:\temp\destcounter.txt" For Binary Access Write As #1 Len = Len(myrecord)
                If Not EOF(1) Then
                    Put #1, , counter1
                End If
            Close #1
           
            destcounter = "1998100500001"
            recnum = 1
            MyPath = "C:\retr\"
         
            If (GetAttr(MyPath) = vbDirectory) Then
                MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
                Do While MyName <> ""   ' Start the loop.
                    If MyName <> "." And MyName <> ".." Then
                        If (GetAttr(MyPath & MyName) And vbDirectory) <> vbDirectory Then
                            filename1 = "C:\retr\" & MyName
                            digit = Right(filename1, 4)
                             
                                                       
                         
                       comm = "C:\Acrobat3\Reader\AcroRd32.exe /t C:\retr\" & MyName & " qcine                                                                                                                KHQCNE.drv  LPT1 "
                         
                       
                           
                      Call Shell(comm, 1)
                        MsgBox (Printer.DriverName)
                       
                   
                       
                       
                   '' Function PrintOut() As Boolean

                     On Error GoTo Err_Handler 'This line goes at top of method

                        'Method code goes here

                        '' PrintOut = True
                        '' Exit Function

Err_Handler:      'This goes at bottom
                Select Case Err.Number
                Case 482, 483, 484
                    MsgBox "Printer Error of " & Err.Description & " " & Err.Number
                Case Else
                MsgBox "Different error of " & Err.Description & " " & Err.Number
                End Select
     '' PrintOut = False
   '' End Function
                     

              Printer.EndDoc
      If Err.Number = 0 Then
           Msg = "Error # " & Str(Err.Number) '& " was generated by " _
           & Err.Source & Chr(13) & Err.Description
            'MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
     
           
                           filename2 = Trim$(Mid(filename1, 9))
                           Address = " Cubbon road"
                           
                         content = recnum & " " & "|" & " " & destcounter & " " & ";" & " " & filename2 & " "                                                           & ";" & " " & Msg & " " & ";" & " " & Address
                          destcounter = destcounter + 1
                         Open "C:\Temp\log.txt" For Append Access Write As #1 Len = Len(myrecord)
                                   Write #1, , content
                         
                          Close #1
           
                               
                                   End If
                       End If
                       End If
                       recnum = recnum + 1
 
                    MyName = Dir
                Loop
            End If


End Sub

Public Sub Main()
    Call cmdDownload_Click
End Sub


0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now