Click to See Complete Forum and Search --> : VB.Net Printing Sequential Access Files


tiggz081
May 26th, 2007, 05:18 PM
I have to print an txt file. The file is setup to display a last name, first name but I need to print out first name space last name.

Here is my code to print the file as is. I need to change it to print the proper way (first name space last name):

Private Sub uiPrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles uiPrintDocument.PrintPage
Dim nameStreamReader As IO.StreamReader
Dim line As String
Dim horizontal As Integer
Dim vertical As Integer
Dim reportFont As New Font("courier new", 12, FontStyle.Regular)

'print report header
e.Graphics.DrawString("Names Report", reportFont, Brushes.Black, 10, 10)
e.Graphics.DrawString("Name", reportFont, Brushes.Black, 10, 55)
e.Graphics.DrawString("-------------------------", reportFont, Brushes.Black, 10, 65)

'open the file
nameStreamReader = IO.File.OpenText("name.txt")
'set the horizontal positin of each print line
horizontal = 10
vertical = 80

'repeat the loop instructions until there are no more characters to read
Do Until nameStreamReader.Peek = -1
'read a line of text from the file, then print the line
line = nameStreamReader.ReadLine()
e.Graphics.DrawString(line, reportFont, Brushes.Black, _
horizontal, vertical)
'update the vertical position for the next print line
vertical = vertical + 15
Loop
'close the file
nameStreamReader.Close()
End Sub
End Class