CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    May 2007
    Posts
    4

    VB.Net Printing Sequential Access Files

    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):
    Code:
    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
    Last edited by Shuja Ali; May 28th, 2007 at 01:53 AM. Reason: Added Code Tags

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

Featured