I've been googling and looking through the older posts
here for a few days now and it looks like I should get
some directional advice for VB6 w/r to printing to
paper.
I'm finding the task of printing to be more formidable
than I thought it would be. Am I missing something or
is it actually this much of a PIA to print to paper in
VB? Might I be missing an Add-in?
I'm not adverse to learning anything new by any
means, but this looks to be a huge task that I'd like
to delay for a bit since I've found a semi-workaround.
I feel like I've been handed a handful of dirt and
asked to start smelting steel<g>! I can't even seem to
find the darned "Print Wizard" the Help refers to and
Google seems to send me to several different,
unverifiable methods of printing, each one different.
What I've ended up doing is just creating a new form,
and populating it onscreen with the needed information
and using currentX, currentY, +50, and a few other
niceties I discovered, and creating an object list to
formulate the lines of text and info I need, and then
just a "Private Sub cmdPrint_Click()" procedure to
print that form. It works, and suffices for now but
it's a lot of monkey work and of course limited to less
than a full page in height.
At least to my way of thinking right now, I'm not in
need or "report generation", although it would work
fine if I could get it to do what I want. But as you
can tell I'm pretty ignorant in this area. What little
bit of printing I've had to do to date has been simple
and easily handled printing right to the form, hiding
some things, and printing away with a Print button.
Works, but not the best solution by far.
Am I just missing the obvious?
Is there an add-in for creating a report or whatever?
I know it can't be as complex as it seems to be, so any
leads to a method to print data to paper would be most
appreciated.
I know I've made all this pretty open-ended but
right now I'm not even sure what the best terminology
to use would be. If examples would help, happy to
supply them, but I suspect I'm just lost because I
can't find a finite start-point. Even a relevant Help
topic might be good<g>.
Thanks for any leads or comments relative to getting
started with this,
Pop`
There might be add-ins, but you sure don't need any. There are lots of ways
to print something. For example, if you wanted to print an existing document
file, you could use the ShellExecute Win32 API function and the "print" verb
to print the document using the document file's associated application. I
don't think that's what you mean though, or want.
The simplest means of printing in VB6 is to use the Printer object. This
pretty much gives you full control of what you print, where it gets printed,
and how it gets printed. Look up "Printer object" in the Index of VB6's
Help.
VB6 (at least Pro and Ent editions) includes the DataReport designer. This
designer is similar to Reports in Access, but does not have nearly as much
functionality or versatility. It's also kind of a pain to work with because
it's designed to use a DataEnvironment (although you can use it without a DE
by using data shaping commands [a feature of ADO], but it's still easier to
at least design the report using a DE because that gives you drag and drop
functionality, lists of fields you can add to the report, etc.). I know of
very few people that will tolerate the DataReport designer for anything
other than the most simplistic of reports and even fewer that actually like
it.
For any kind of complex report, you're better off using a 3rd party
reporting tool, such as Crystal Reports (not advocating CR, just mentioning
it).
For my own purposes, if printing a report from a VB6 app, 95% of the time I
get by just fine using VB's Printer object. I suppose I use the DR designer
*maybe* 1% of the time and Crystal Reports the other 4%. Since a large part
of what I do is customizations to Microsoft's business product Solomon and
Sage Software's MAS 500 (both written with VB6) and they both use CR, I
actually use CR a decent amount, just not so much from 'scratch" VB6 apps
that I write.
--
Mike
Microsoft MVP Visual Basic
Now I have a Form for printing. It has numerous sets of controls, all
invisible. I have three different forms I have to print all or part of. I
copy the info to the print form and make those controls visible. So now my
print form looks just the way I want it.
I now call the magic routine which effectively puts a screenshot into a
picture box then resizes the picture box to fit the printer size then prints
it. (whew)
This gets the code: http://home.surewest.net/galen/download/print.zip
Galen
> I'm finding the task of printing to be more
> formidable than I thought it would be. Am
> I missing something or is it actually this much
> of a PIA to print to paper in VB?
Printing is fairly straightforward once you get the hang of it. There are of
course various good commercial third party addins that allow you to easily
create and print reports, but you really don't need them because you can get
excellent results using the VB Printer Object properties and methods
(CurrentX, CurrentY, Print, Line, Circle, PaintPicture, etc, etc). The one
major thing that the VB Printer Object does not natively do is wrapped
blocks of text, but you can still use it for printing such wrapped blocks
either by calculating the wrapping points yourself in code or alternatively
by using the DrawText API on the VB Printer Object's hDC which will wrap the
text for you. And of course there are all sorts of other ways of doing it.
One thing that I would definitely suggest you do NOT do is to print VB
Forms, either using the PrintForm method you are currently using or the
method in the link posted by Galen, because the output resolution is simply
not good enough for anything other than rough draft copies.
Mike
Thanks, guys, that was good, useful input. Some good
pointers to keep in mind, too. Coupled with the
Printer Collections I also came upon, I think I'm off
and running. It's always hardest to get started I
guess.
Regards to all,
Pop`