469,934 Members | 1,632 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

infinity loop in PrintPreviewDialog

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

Nov 20 '05 #1
4 3035
Cor
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
Nov 20 '05 #2
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()

-----Original Message-----
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 havethe 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
.

Nov 20 '05 #3
Cor
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
Nov 20 '05 #4
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
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael A. Covington | last post: by
reply views Thread by Harry J. Smith | last post: by
1 post views Thread by Jack E. Hardie | last post: by
1 post views Thread by jacopomeucci | last post: by
2 posts views Thread by Richard MSL | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.