Question
Visual Basic (NOT VBA for Excel): The code below prints 1 page of data from a text file and stops without printing the rest of
Visual Basic (NOT VBA for Excel): The code below prints 1 page of data from a text file and stops without printing the rest of the data in the file. (The text file contents are included at the end of the code.) There are enough records in the file to print a complete page 1 and start 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
Records.txt
Syker
Mike
1
1258 Wilder Ave.
Lima
OH
44836
456-789-2291
500.00
5/30/2017
Glee
Grace
2
12334 Main St.
Lima
OH
44836
456-123-7458
23.00
5/2/2017
Smith
Mark
3
23 Sky Drive
Lima
OH
44836
456-789-6588
58.00
5/2/2017
Martin
Mary
4
789 Cross St.
Lima
OH
44836
789-369-5544
500.00
5/4/2017
Jones
Jim
5
12 Kline Dr.
Lima
OH
44839
456-987-6636
98.89
5/8/2017
Deen
Jon
6
54 Lemon Lane
PHX
AZ
85693
480-851-8803
.37
7/29/2017
Nofts
Paul
7
123 Wilder Ave.
Lima
OH
44836
409-433-8562
56.00
5/3/2017
Wargo
Paul
8
1236 Wilder Ave.
Lima
OH
44836
456-789-3625
500.00
6/8/2017
Thanks for the help!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started