472,338 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,338 software developers and data experts.

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 3095
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael A. Covington | last post by:
By default, my PrintPreviewDialog is coming out too small. What is the best way to control its size and position? Ideally, I'd just like to...
2
by: Randy | last post by:
Hello all, I'm trying to print using PrintPreviewDialog. What's happening is that the PrintPreviewDialog shows the correct information to be...
3
by: sachin | last post by:
How to customize PrintPreviewDialog, such that, addition of a new button, change the functionality of existing button should be possible...
0
by: Harry J. Smith | last post by:
I am using the PrintPreviewDialog Window Form from the Toolbox. It displays my RichTextBox contents correctly, but when I click on the Print icon...
1
by: Jack E. Hardie | last post by:
When I call the PrintPreviewDialog, the resulting default window and zoom size are too small to read. I have figured out how to resize the window,...
1
by: Darrell Wesley | last post by:
Is there anyway to hook the PrintDialog to the printer icon on the PrintPreviewDialog? I know that you can print a document using the PrintDialog...
1
by: jacopomeucci | last post by:
hi all. I've a problem with PrintPreviewDialog in c#. I've done a form with a ListViewControl and i tried to print the data contents in this...
2
by: Richard MSL | last post by:
I am using PrintPreviewDialog to preview a file. There is a button that the user can press, which seems to print the file to the default printer. I...
10
by: choupi | last post by:
Hello, Is there a way to call a printDialog from a printPreviewDialog (from print icon for example)? Indeed, the print icon in the...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.