Printing from VB.NET - Frustrated, Code please!

A

al jones

I'll try again as I'm obvioulsy standing in the middle of the forest and
not seeing the trees ... I didn't think I was to old to learn new trick,
but this has just about convinced me otherwise. I just don't see how using
gdi to drop lines of text out to the printer ...

I'm converting a very old GWBASIC program - I now have it writing to a file
and I can print the file but that's not what I want to do (page breaks /
widows / orphans / etc). Would some kind soul give me the code I'd need in
my program to replace the following WriteLines with output to a printer - I
just can't see it (here's a sample of about 800 lines of spaghetti code):

PrintHeader(Me.cbPrintHeader.Checked)
myFile.WriteLine("")
L77: P = R - 0.3
L78: myFile.WriteLine("RADIUS TO OUTSIDE 1ST LANE LINE = " + Str(P) + "
(METERS)")
myFile.WriteLine("") : myFile.WriteLine(" ALL OTHER MEASURMENTS
HEREIN ARE IN METERS")
H = intL1Distance / 2 - 200
R1 = R
Z = F + (Q * H)
L88: myFile.WriteLine("") : myFile.WriteLine(" " + Str(Q) +
"TURN STAGGER") : myFile.WriteLine("")
If Q = 1 Then GoTo L210
If Q = 3 Then GoTo L210
L95: If Z > 0 Then GoTo L145
myFile.WriteLine(PrintRadius(intCounter, R, 1, Z))
GoTo L107
L106: myFile.WriteLine(PrintDegrees(intCounter, Int(Z), (Int(B)),
Int(G)))
L107: If M = 20 Then GoTo L110

My emails easy enough to decipher if you'd like to do it for fee - give me
an idea ....
 
R

Ron Allen

Al,
I'm not sure this is adaptable directly to a PrintDocument output as the
way PrintDocument OnPrintPage works it returns from that function setting
HasMorePages to true when there are more pages and false when done. The
exit from this function produces the required page eject/formfeed to the
printer.

You would probably do better using direct output to the printer or
intermediate files (as you have already tried) as the logic in this is all
tangled up in the output. The way I would do this as I'm used to doing an
intermediate output file would be to write an intermediate file and then
read and paginate that file for output as lines of text.

In my code I write the output as an XmlDocument first and then use that
to produce a paginated XmlDocument where every <page> element is a seperate
document page. This is written to disk for transmission offsite and also
printed using a specialized PrintDocument subclass that reads the XML
elements and renders them on the page. I could probably use some other form
of tagged output but XML is easier to read when debugging and DOM has the
tools necessary to check for null/missing nodes that may occur.

If you had just one page of output you could wrap the whole thing in an
OnPrintPage handler and just use DrawString followed by incrementing the y
position on the page for each WriteLine but since you say you have multiple
pages this wouldn't work.

If I was doing this I'd first do a logic diagram of the whole program
flow and then write new code to produce the same result. I've had to
convert some old Fortran code written like this using computed gotos, etc.
to Ada and that was really difficult when there wasn't any formatted output
being done.

Ron Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top