473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 3138
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 maximize it. Thanks!
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 printed, but when I click the print icon, it prints a...
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 programatically. Sample code will help a lot. Moreover, what...
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 on this form it prints one blank page and no text....
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, but can someone help me with the call to preset...
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 but it does not allow previewing and the...
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 listview. I've read the ListViewControl via a...
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 would like to capture a click on that button so...
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 printpreviewdialog prints directly the document without...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.