469,643 Members | 1,905 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Printing from VB.NET - Frustrated, Code please!

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 ....
Nov 21 '05 #1
1 1519
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
"al jones" <al**********@shotmail.com> wrote in message
news:1g******************************@40tude.net.. .
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 ....

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Jody Gelowitz | last post: by
4 posts views Thread by Arif | last post: by
3 posts views Thread by D Witherspoon | last post: by
18 posts views Thread by Brett | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.