infinity loop in PrintPreviewDialog

  • Thread starter Thread starter Kwok
  • Start date Start date
K

Kwok

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
 
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
 
Hi, Cor

thanks for your sugestion, but I tried your code, It also
did a infinity loop. The infinity loop happened in
PrintPreviewDialog load a document.

here is my code
dim pDoc as PrintDocument
dim pDialog as new PrintPreviewDialog()

pDoc = New PrintDocument()
pDoc.DefaultPageSettings.Landscape = True
AddHandler pDoc.PrintPage, AddressOf printJobSchedule
pDialog.Document = pDoc
pDialog.ShowDialog()
 
Kwok,
I have made a new project and pasted this code into the sub with the load
document event.
The document shows up.
Therefore I think there cannot be an infinity loop.
But maybe you can try it too and tell me what I did wrong?
Cor
 
Cor,

sorry, I made a mistake from your code. But I tried your
code (I also create a new windows form project), it only
showed one page which including all records.

I changed your code.

If JobCount > 0 Then
*Dim dummy As Boolean = True
* I change above code to
ev.hasMorePage = true
End If
loop

then It made a infinity loop.

I tried use boolean to check more page then
write a ev.hasMorePage above for loop or under if statment.
but it is also infinity

SO, can you have some idea to what is the code wrong??
how to print more pages??

Thanks
Kwok
 
Back
Top