Results 1 to 2 of 2

Thread: Print Line By Line

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2010
    Posts
    24

    Print Line By Line

    Can i print line by line in vb.net ...

    i am using a dot matrix printer ... is it possible ...
    actually i have a class in vb 6.0 that generate a line by line print but don't know how to convert it in .net ...

    here is the code in vb 6.0

    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
    
    Dim lhPrinter As Long
    
    Public Function NewPage(Optional PrinterName As String, _
                            Optional DocName As String) As Boolean
        On Error GoTo NewPage_Error
    
        If PrinterName = "" Then PrinterName = Printer.DeviceName
        If DocName = "" Then DocName = Application.Name
    
        Dim lReturn As Long
        Dim lDoc As Long
        Dim MyDocInfo As DOCINFO
    
        lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
        If lReturn = 0 Then
            MsgBox "No Printer selected!", vbExclamation
            NewPage = False
            Exit Function
        End If
            
        MyDocInfo.pDocName = DocName
        MyDocInfo.pOutputFile = vbNullString
        MyDocInfo.pDatatype = vbNullString
        lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
        Call StartPagePrinter(lhPrinter)
            
        NewPage = True
    
        On Error GoTo 0
        Exit Function
    NewPage_Error:
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure NewPage of Class Module clsPrintLineByLine"
        NewPage = False
        End Function
    
    Public Sub PrintLine(ByVal srcToPrint As String)
        Dim lReturn As Long
        Dim lpcWritten As Long
        Dim sWrittenData As String
        sWrittenData = srcToPrint & vbCrLf
        lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
                               Len(sWrittenData), lpcWritten)
    End Sub
    
    Public Sub EndPage()
        Dim lReturn As Long
    
        lReturn = EndPagePrinter(lhPrinter)
        lReturn = EndDocPrinter(lhPrinter)
        lReturn = ClosePrinter(lhPrinter)
    End Sub

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Print Line By Line

    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width