Announcement

Collapse
No announcement yet.

PBDLL Print Query

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBDLL Print Query

    I would be grateful for any help on the following printing query.

    I am trying to print plain text reports, pre-formatted within the program, to a network
    printer (Epson SQ1170) in draft mode without using the Windows printing system, by opening
    and printing to the print queue as a device. I would prefer not to have to send the data
    to a file and then print the file.

    The following PB/DLL 6 code will not work at all using a network printer but work perfectly
    well using LPT1 with the printer locally attached to the parallel port.

    The Visual Basic 6 code however, works perfectly without any problems so am I missing
    something here - maybe a missing include file - as there is obviously something in
    Visual Basic which is not in PB/DLL?

    I have searched through all the back archives in the forums, and it seems that the
    code is correct.

    I apologise in advance if this has been fully covered and I have missed it, but if
    anyone has any suggestions I would be very grateful, as, for printing this type
    of report, I would like to keep it as simple as possible without getting into full
    Windows printing methods at the moment. I have found numerous code examples, but they
    all seem much too complex for what I am trying to achieve.
    Code:
    '==============================================================
    '... PB/DLL 6 CODE ...
    
    #Dim All
    #Register None
    #Compile Exe
    
    #Include"WIN32API.INC"
    #Include"COMMCTRL.INC"
    #Include"COMDLG32.INC"
    
    Function PbMain() As Long
    
        Dim i As Long
        Dim strDistribution As String
    
        strDistribution = "CW,CF,HE,NG,BL,BF,JK,RC"
    
        Open "\\BATH_PRESS\COMPUTERQ0" For Output As #1
    '    OPEN "LPT1:" FOR OUTPUT AS #1
    
        Print #1, "Date produced:                    " & _
                  "BATH PRESS LTD. : DEPARTMENTAL V.O.P REPORT"
        Print #1,
        Print #1, "NUMBER OF DAYS = 5
        Print #1,
        Print #1, "   DEPARTMENT"
        Print #1, "                                                     " & _
                  "Hours       V.O.P.        Hours       V.O.P.        " & _
                  "Hours       V.O.P."
        Print #1, "                               " & _
                  "|---------------------------|-----------|-------------" & _
                  "|-----------|-------------|-----------|"
        Print #1,
        Print #1, strDistribution
    
        For i = 1 To 50
            Print #1, i
        Next i
    
        PRINT #1, CHR$(12)
    
        Close #1
    
    End Function                                                
    
    '=========================================================================
    '... VISUAL BASIC 6 CODE ...

    Option Explicit

    Private Sub Form_Load()

    Dim i As Long
    Dim strDistribution As String

    strDistribution = "CW,CF,HE,NG,BL,BF,JK,RC"

    Open "\\BATH_PRESS\COMPUTERQ0" For Output As #1

    ' Open "LPT1" For Output As #1

    Print #1, "Date produced: " & _
    "BATH PRESS LTD. : DEPARTMENTAL V.O.P REPORT"
    Print #1,
    Print #1, "NUMBER OF DAYS = 5"
    Print #1,
    Print #1, " DEPARTMENT"
    Print #1, " " & _
    "Hours V.O.P. Hours V.O.P. " & _
    "Hours V.O.P."
    Print #1, " " & _
    "|---------------------------|-----------|-------------" & _
    "|-----------|-------------|-----------|"
    Print #1,
    Print #1, "Distribution: " & strDistribution

    For i = 1 To 50
    Print #1, i
    Next i

    Print #1, Chr$(12)

    Close #1

    End Sub

    ------------------

  • #2
    I just tried your print code with PB/DLL 6.0 and it worked fine for me across my network here to "\\server\ibm" (a Star 9p dotmatrix printer installed as an IBM Proprinter II).

    (I do have that printer SHARED on \\SERVER and the driver installed as a network printer on the client machine... I did not try it without the local driver installed, but it should not make any difference (AFAIK anyway).

    I'd suggest that you add some error checking code to see if there are any run-time errors (ERR and ERRAPI) when the code runs, such as the OPEN statement failing for some reason.

    I hope this helps!


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance

      Thank you for your very quick reply.

      I have put in some error trapping and am getting an error 51 - Internal
      Error when trying to open the printer.

      Incidentally, I forgot to mention that this is running on Novell 5.0
      and that COMPUTERQ0 is the print queue name

      Alan

      ------------------

      Comment


      • #4
        Ok, the error 51 means there was an unexpected or unknown error.

        The problem here is almost certain to be Novell - I recall problems with PB/CC users using UNC names with LPRINT ATTACH "\\unc\name" *just* on Novell networks.

        You can double check it by running the code on a MS network.

        Anyone have any suggestions, solutions, or workarounds to offer? I don't have access to a Novell network to test with...


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          A workaround might be to CAPTURE the print queue to a (local) LPT-Port.

          From the command line that would loook like:

          CAPTURE /L=<LPT-Port> /S=<Server name> /Q=<Print queue name> N<o>B<anner> N<o>T<ab> TI<meout>=10
          i.e.
          CAPTURE /L=1 /S=bath_press /Q=computerq0 NB NT TI=10

          and then simply print to LPT1

          Knuth

          ------------------
          http://www.softAware.de

          Comment


          • #6
            Why do not write to a file and then CopyFile "myfile", "prn" (or lpt1 , %False
            Let's Windows works.

            ------------------
            E-MAIL: [email protected]

            Comment


            • #7
              Here's a simple application that is used for printing to about
              3,000 POS receipt & thermal transfer printer from a web server.
              It sends the printer-native file in RAW mode through the
              print spooler, bypassing the graphical rendering engine.

              I use Generic / Text Only drivers for these printers, which
              are small, and already available on all client PC's. A
              custom MIME type is used to call the app. Control info is
              added to the printjob file to route portions of the file
              to the correct printer.

              You will probably only need SpoolPrint function...
              Code:
              '----------------------------------------------------
              ' Program: Printer Spooler
              ' Purpose: Send a label or receipt printer file
              '          directly to the printer, bypassing
              '          the print driver.  Used for files
              '          having native printer commands, for
              '          Epson ESC/POS and Datamax DPL printers,
              '          among others.
              ' Author:  Charles V. Hicks
              ' Date:    05/24/2001
              '----------------------------------------------------
              
              #COMPILE EXE
              #INCLUDE "win32api.inc"
              
              SUB SpoolPrint(PrinterName AS STRING, PrintData AS STRING)
              
                  DIM lhPrinter AS LONG
                  DIM lReturn AS LONG
                  DIM lpcWritten AS LONG
                  DIM pPrinterName AS ASCIIZ * 255
                  DIM PrintJobName AS STRING
                  DIM pBuf AS ASCIIZ * 1
                  DIM MyDocInfo AS DOC_INFO_1
                  DIM RecLen AS LONG
                  DIM DataType AS STRING
                  DIM i AS INTEGER
              
                  DataType = "RAW" & $NUL
                  pPrinterName = PrinterName
                  PrintJobName = PrinterName
              
                  MyDocInfo.pDocName = STRPTR(PrintJobName)
                  MyDocInfo.pDataType = STRPTR(DataType)
              
                  lReturn = OpenPrinter(pPrinterName, lhPrinter, BYVAL 0)
                  IF lReturn = 0 THEN
                      MSGBOX "Error Opening Printer: '" & pPrinterName & "'" & $CRLF & _
                             "Please make sure a printer driver named" & $CRLF & _
                             "'" & PrinterName & "' is installed for this printer.", _
                             %MB_OK OR %MB_ICONERROR, _
                             "Print Error"
                      EXIT SUB
                  END IF
              
                  lReturn = StartDocPrinter(lhPrinter, 1, MyDocInfo)
                  lReturn = StartPagePrinter(lhPrinter)
              
                  FOR i = 1 TO LEN(PrintData)
                      pBuf = MID$(PrintData, i, 1)
                      lReturn = WritePrinter(lhPrinter, pBuf, 1, lpcWritten)
                  NEXT i
              
                  lReturn = EndPagePrinter(lhPrinter)
                  lReturn = EndDocPrinter(lhPrinter)
                  lReturn = ClosePrinter(lhPrinter)
              
              END SUB
              
              SUB ParseLine(lne AS STRING, cmd AS STRING, parm AS STRING)
              
                  DIM work AS STRING
                  DIM delimiter AS STRING * 1
              
                  delimiter = "="
                  cmd = ""
                  parm = ""
              
                  IF LEFT$(lne, 1) = "[" AND RIGHT$(lne, 1) = "]" THEN
                      work = TRIM$(lne, ANY "[]")
                      IF PARSECOUNT(work, delimiter) = 2 THEN
                          cmd = PARSE$(work, delimiter, 1)
                          parm = PARSE$(work, delimiter, 2)
                      ELSE
                          cmd = work
                          parm = $NUL
                      END IF
                  END IF
              
              END SUB
              
              '-- Program entry point
              FUNCTION PBMAIN() AS LONG
              
                  DIM PrintJobName AS STRING
                  DIM PrintFileName AS STRING
                  DIM PrinterName AS STRING
                  DIM PrinterType AS STRING
                  DIM Extension AS STRING
                  DIM hFile AS INTEGER
                  DIM lne AS STRING
                  DIM Cmd AS STRING
                  DIM Parm AS STRING
                  DIM PrintData AS STRING
              
                  '-- Initialize printer name
                  PrinterName = $NUL
              
                  '-- Name of file to be printer from command line
                  '-- Strip leading and trailing quote characters, if necessary
                  PrintFileName = TRIM$(COMMAND$, CHR$(34))
                  PrintJobName = PrintFileName
              
                  '-- If the file doesn't exist, notify user and exit
                  IF DIR$(PrintFileName) = "" THEN
                      MSGBOX "File Not Found: '" & PrintFileName & "'", _
                             %MB_OK OR %MB_ICONERROR, _
                             "Print Error"
              
                      EXIT FUNCTION
                  END IF
              
                  hFile = FREEFILE
                  OPEN PrintFileName FOR INPUT SHARED AS #hFile
              
                  DO UNTIL EOF(hFile)
                      LINE INPUT #hFile, lne
                      CALL ParseLine(lne, cmd, parm)
                      SELECT CASE LCASE$(cmd)
                          CASE "printjob"
              
                          CASE "version"
              
                          CASE "printertype"
                              PrinterType = parm
                          CASE "printername"
                              PrinterName = parm
                          CASE "begin_data"
                              PrintData = $NUL
                              DO UNTIL EOF(hFile)
                                  LINE INPUT #hFile, lne
                                  IF LCASE$(lne) = "[end_data]" THEN
                                      IF PrinterName <> $NUL AND PrintData <> $NUL THEN
                                          CALL SpoolPrint(PrinterName, PrintData)
                                      END IF
                                      EXIT DO
                                  END IF
                                  PrintData = PrintData & lne & $CRLF
                              LOOP
                      END SELECT
                  LOOP
              
                  '-- Clean up and exit
                  CLOSE
                  EXIT FUNCTION
              
              END FUNCTION
              ------------------

              Comment


              • #8
                Thank you all for your replies

                The CAPTURE option works fine - I am using it in the user's login
                scripts rather than in the program itself.

                I'm sure that I had already tried that originally without success
                so I must have done something wrong then.

                Thanks again

                Alan

                ------------------

                Comment


                • #9
                  Just to make a clarification: "LPRINT ATTACH \\server\queue" will work fine in a bindery based network (i.e. Netware 3.x). I've not had any lusk with gettign that format to work with NDS based queues (nw4.x and 5.x). I plug away at it when I have free time, but no real headway yet. I'm going to get some docs from the novell developer's forum and see if there's some wisdom there.



                  ------------------
                  [email protected]
                  http://www.northnet.org/bdurland
                  Real programmers use a magnetized needle and a steady hand

                  Comment

                  Working...
                  X