Board index » Visual Studio » infinity loop in PrintPreviewDialog

infinity loop in PrintPreviewDialog

Visual Studio120
Hi,



I want to print some record(s) from dataset.table(tbname)

using PrintPreviewDailog and PrintDocument. But It has a

infinity loop error.



I use a class to control the print procedure.



Here is my code.



Public Sub New(ByVal dbset As DataSet)

jobFont = New Font("Times New Roman", 12)

myJobSet = dbset

pDoc = New PrintDocument()

pDoc.DefaultPageSettings.Landscape = True

AddHandler pDoc.PrintPage, AddressOf printJobSchedule

pDialog.Document = pDoc

pDialog.ShowDialog()

End Sub



'PrintDocument

Private Sub printJobSchedule(ByVal sender As Object, ByVal

ev As PrintPageEventArgs)



JobCount = myJobSet.Tables("Orders").Rows.Count

reJob = myJobSet.Tables("Orders").Rows.Count

yPos = 120

curJob = 0

JobPerPage =5



Do While JobCount>= 1



For count = 1 To jobPerPage



'Print some record(s) here



curJob += 1

reJob -= 1

If reJob = 0 Then

Exit For

End If

Next



JobCount -= 5

If JobCount>0 Then

ev.HasMorePages = True

End If

Loop



End Sub



IS my code got any mistake??



Thanks,

KWOK


-
 

Re:infinity loop in PrintPreviewDialog

Hi Kwok,

I did test it with this code.

It did not give an infinity loop.

Maybe you can too bring your variables into the routine, then you don't have

the problem that maybe somewhere outside it can be change

\\\\\\

Dim JobCount As Integer = 1000

Dim reJob As Integer = 100

Dim curJob As Integer = 0

Dim JobPerPage As Integer = 5

Do While JobCount>= 1

Dim count As Integer

For count = 1 To jobPerPage

'Print some record(s) here

curJob += 1

reJob -= 1

If reJob = 0 Then

Exit For

End If

Next

JobCount -= 5

If JobCount>0 Then

Dim dummy As Boolean = True

End If

//////////////

Cor





-