dcsimg
Results 1 to 5 of 5

Thread: [RESOLVED] use printer.print print escape <ESC> problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Resolved [RESOLVED] use printer.print print escape <ESC> problem

    Hi,
    good day to you.
    may i know how to use printer.print to print <ESC> in prn file.

    below output only have 1 dot (.)
    Code:
    Private Sub Command2_Click()
    
    Dim VbEsc As String
    
    VbEsc = Chr$(27)
    
    Printer.Print VbEsc
    Printer.EndDoc
    
    
    End Sub
    your help is much appreciated.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,243

    Re: use printer.print print escape <ESC> problem

    "HOWTO: Send Raw Data to a Printer Using the Win32 API from Visual Basic" is no longer on Microsoft's support site, but you can find this Q154078 in the October 2001 MSDN CDs and maybe even a few earlier editions.

    The Visual Basic Printer object allows for printing through printer drivers, but there may be times when it is desirable to use the Win32 API to send information more directly to the printer. The code sample to follow shows how to achieve this by using API functions that bypass printer drivers to communicate directly with the print spooler.
    Code:
          Option Explicit
    
          Private Type DOCINFO
              pDocName As String
              pOutputFile As String
              pDatatype As String
          End Type
    
          Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
             hPrinter As Long) As Long
          Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
             hPrinter As Long) As Long
          Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
             hPrinter As Long) As Long
          Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
             "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
              ByVal pDefault As Long) As Long
          Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
             "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
             pDocInfo As DOCINFO) As Long
          Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
             hPrinter As Long) As Long
          Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
             hPrinter As Long, pBuf As Any, ByVal cdBuf As Long,  _
             pcWritten As Long) As Long
    
          Private Sub Command1_Click()
              Dim lhPrinter As Long
              Dim lReturn As Long
              Dim lpcWritten As Long
              Dim lDoc As Long
              Dim sWrittenData As String
              Dim MyDocInfo As DOCINFO
              lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
              If lReturn = 0 Then
                  MsgBox "The Printer Name you typed wasn't recognized."
                  Exit Sub
              End If
              MyDocInfo.pDocName = "AAAAAA"
              MyDocInfo.pOutputFile = vbNullString
              MyDocInfo.pDatatype = vbNullString
              lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
              Call StartPagePrinter(lhPrinter)
              sWrittenData = "How's that for Magic !!!!" & vbFormFeed
              lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
                 Len(sWrittenData), lpcWritten)
              lReturn = EndPagePrinter(lhPrinter)
              lReturn = EndDocPrinter(lhPrinter)
              lReturn = ClosePrinter(lhPrinter)
          End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Re: use printer.print print escape <ESC> problem

    Hi,
    thank you for your info, i only need to CHR$(27) symbol in prn file when i use printer.print method for send text to prn file.

    refer below screenshot.

    Name:  prn1.jpg
Views: 59
Size:  26.7 KB

    Name:  prn2.jpg
Views: 55
Size:  30.0 KB
    Last edited by hwkong1688; Jul 11th, 2018 at 09:45 AM.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Re: use printer.print print escape <ESC> problem

    Hi,
    i follow your suggestion, finally managed to solved.

    thank you.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    108

    Re: use printer.print print escape <ESC> problem

    Hi,
    i follow your suggestion, finally managed to solved.

    thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width