Question : Print raw data to the printer:

I am trying to use: Accepted Answer from iboutchkine Date: 08/27/2003 06:56PM PDT, on printing the raw data. Contained in my
comma delimited file, I have 11-fields per record to be printed on envelopes. I also have used the split function of vb.net to array the field values (values(0), values(1),....). Up to this point all seems to work except there is no print-out. When I look at the print queue
there are multiple documents (60+) waiting to be printed. Also, would you please point me in the right direction for a routine for displaying a dialog box for envelope printing. I included my code so you can see where I went wrong.

thanks,
mike

mports System
Imports System.IO
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

  #End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Try
        ' Create an instance of StreamReader to read from a file.
        Dim sr As StreamReader = New StreamReader("c:\ccmate\StateCDelim.txt")
        Dim line As String
        Dim values() As String
        Dim Add1, Add2, City, State, Zip, Dept, Attn, _
        Div, Phone, FPhone, WSite, line2 As String
        Dim pd As New PrintDialog
        pd.PrinterSettings = New PrinterSettings
        ' Read and display the lines from the file until the end
        ' of the file is reached.
        Do
            line = sr.ReadLine()
            values = Split(line, ",")
            Add1 = values(0)
            Add2 = values(1)
            City = values(2)
            State = values(3)
            Zip = values(4)
            Dept = values(5)
            Attn = values(6)
            Div = values(7)
            Phone = values(8)
            FPhone = values(9)
            WSite = values(10)
            line2 = Dept & vbCrLf
            If Attn <> "" Then
                line2 = line2 & vbCrLf & Attn
            End If
            If Div <> "" Then
                line2 = line2 & vbCrLf & Div
            End If
            line2 = vbCrLf
            ' If pd.ShowDialog(Me) Then
            ' Print the first 3-lines
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            line2 = Add1
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            line2 = vbCrLf
            ' Print Add1
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            If Add2 <> "" Then
                line2 = Add2
                ' Print Add2
                RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            End If
            line2 = vbCrLf
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            ' Print City, State, Zip
            line2 = City & ", " & State & " " & Zip
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            ' Print Phone and FPhone
            line2 = vbCrLf
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            line2 = Phone & "    " & FPhone
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            line2 = vbCrLf
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            ' Print Wsite
            line2 = WSite
            RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, line2)
            Console.WriteLine(line)
            '   End If
        Loop Until line Is Nothing
        sr.Close()
        'Catch E As Exception
        ' Let the user know what went wrong.
        ' Console.WriteLine("The file could not be read:")
        'Console.WriteLine(E.Message)
        'End Try

    End Sub
End Class
Public Class RawPrinterHelper
.
.
End Class

Answer : Print raw data to the printer:

Look in the routine SendBytesToPrinter.
Random Solutions  
 
programming4us programming4us