Question: Visual Basic: The code below prints 1 page of data from a text file and stops without printing the rest of the data in the
Visual Basic: The code below prints 1 page of data from a text file and stops without printing the rest of the data in the file. There are enough records in the file to print a complete page 1 and strat page 2, but page 2 never starts. How do I get this routine to print more than one page?
Private Sub printCustomerReport_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles printCustomerReport.PrintPage
Dim count As Integer = 0
Dim intVertPos As Integer
e.Graphics.DrawString("Customer Account Report", New Font("Courier New", 12, FontStyle.Bold), Brushes.Black, 200, 10)
' ID the file to open.
txtfileName = "Records.txt"
' Open the file to read the records.
txtFile = File.OpenText(txtfileName)
' Use the setData function to place the file data into the text boxes
setData()
searchFile = File.OpenText(txtfileName)
intVertPos = 50
Try
' Read the file to end of file.
' Print the contents to the PrintDocument.
While Not searchFile.EndOfStream
If count = 10 Then
count = 0
intVertPos += 20
Else
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "Last Name:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "First Name:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "Customer Number:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "Address:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "City:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "State:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "ZIP Code:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "Telephone Number:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "Account Balance:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
e.Graphics.DrawString(String.Format("{0,20}{1,10}", "Date of Last Payment:",
searchFile.ReadLine()),
New Font("Courier New", 12, FontStyle.Regular),
Brushes.Black, 15, intVertPos)
intVertPos += 15
count += 1
End If
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Thanks for the help!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
