Discussion:
VB6, printing on Deafult printer
(too old to reply)
Johan Stäck
2007-09-06 06:33:29 UTC
Permalink
Hello!

I have this VB6 application that prints on the designated default printer.
The program doesn't in itself have any functionality for selecting a
printer or doing printer setup.
If no printer is found, the program will inform the user about this, and
all printing functions are disabled.

Some time ago I was installing the program at a customer site and there
was both a local printer and a network printer, and there was a lot of
"fiddling" with printer drivers, network issues etc. It was all a mess.

I encountered a nasty bug (in the printer handling)in my own program.
The reason was that in some way I had managed to create the situation
where the PC running my program "saw" only one printer, but this printer
was *not* designated as default printer. I.e. there was no default printer.

Now, I have tried to re-create this situation (one printer, *not*
designated as default), but I am not able to do it.
Windows seems always (quite logically) to designate a single remaining
printer as being default.

Og course I am afraid that a customer will eventually again be creating
the situation that caused the nasty bug, and I want to catch it..

Anyone with ideas on how to recreate the "one-printer-not-being-default"
situation?

Tia

/Johan Stäck
Skelleftå
Sweden
JP Bless
2007-09-06 14:05:37 UTC
Permalink
One quick way is to read the printers collection into a listbox, combobox
etc; and have a way for the user to (be able) to select which printer should
handle your VB project print job. The user should be able to save the
selected printer to the registry or an INI so your app remembers which
printer to handle the print job next time.

For VB to send print job to designated printer

Have a look at
http://www.freevbcode.com/ShowCode.asp?ID=3646

http://www.freevbcode.com/ShowCode.asp?ID=641
Post by Johan Stäck
Hello!
I have this VB6 application that prints on the designated default printer.
The program doesn't in itself have any functionality for selecting a
printer or doing printer setup.
If no printer is found, the program will inform the user about this, and
all printing functions are disabled.
Some time ago I was installing the program at a customer site and there
was both a local printer and a network printer, and there was a lot of
"fiddling" with printer drivers, network issues etc. It was all a mess.
I encountered a nasty bug (in the printer handling)in my own program.
The reason was that in some way I had managed to create the situation
where the PC running my program "saw" only one printer, but this printer
was *not* designated as default printer. I.e. there was no default printer.
Now, I have tried to re-create this situation (one printer, *not*
designated as default), but I am not able to do it.
Windows seems always (quite logically) to designate a single remaining
printer as being default.
Og course I am afraid that a customer will eventually again be creating
the situation that caused the nasty bug, and I want to catch it..
Anyone with ideas on how to recreate the "one-printer-not-being-default"
situation?
Tia
/Johan Stäck
Skelleftå
Sweden
Johan Stäck
2007-09-06 17:17:22 UTC
Permalink
Post by JP Bless
One quick way is to read the printers collection into a listbox, combobox
etc; and have a way for the user to (be able) to select which printer should
handle your VB project print job. The user should be able to save the
selected printer to the registry or an INI so your app remembers which
printer to handle the print job next time.
For VB to send print job to designated printer
Have a look at
http://www.freevbcode.com/ShowCode.asp?ID=3646
http://www.freevbcode.com/ShowCode.asp?ID=641
Yes, that is interesting and relevant information.
However, my problem is the behaviour of the printer object that occurs
when there is one printer availible that isn't designated as the default
printer.
I *did* manage (by mistake, in a chaotic environment) to create that
situation, and I would like to re-create it. (but I haven't succeeded,
in spite of lots of trying..)
Admitted, this is not really a pure VB6 problem but perhaps more generic
Windows...

/Johan
Mike Williams
2007-09-06 18:34:39 UTC
Permalink
Post by Johan Stäck
Yes, that is interesting and relevant information.
However, my problem is the behaviour of the printer
object that occurs when there is one printer availible
that isn't designated as the default printer. I *did* manage
(by mistake, in a chaotic environment) to create that situation, and I
would like to re-create it. (but I haven't
succeeded, in spite of lots of trying..)
You haven't really given us a lot to go on, and you did say in your original
post that there was "a lot of fiddling with the printer drivers and network
issues" at the time, so it could be almost anything, but my guess is that
you deleted (or otherwise changed) the printer that the VB printer object
was pointing to while your VB app was running. Under certain circumstances
this can cause problems such as the one you describe.

For example, suppose that you have two printer drivers installed (PrinterA
and PrinterB) and that PrinterA is the system default printer at the time
you start your VB program. Also suppose that you have either deliberately or
accidentally set the VB Printer Object's PrinterDefault property to False,
causing it to fail to track the default printer. If you now use Control
Panel while your VB app is still running to change the system default to
PrinterB then VB will be left pointing to PrinterA, which is no longer the
system default printer. In fact VB will still be pointing to PrinterA even
if you delete PrinterA from your system. This of course will cause your
program to stop with an error as soon as it attempts to print something,
because the driver it is pointing to no longer exists. Anyway, in the
absence of further information from you, that would be my guess as to what
might have happened.

Mike
Mike Williams
2007-09-07 04:27:28 UTC
Permalink
Post by Johan Stäck
I *did* manage (by mistake, in a chaotic environment) to
create that situation, and I would like to re-create it.
By the way, further to my initial response, you don't need to go looking for
specific lines of code in your project that changed the Printer.TrackDefault
property to False from its default value of True, because this will probably
have been done implicitly rather than explicitly.

To explain what I mean, the VB Printer object works by checking the current
default printer and its current settings when you start a print job, and
sometimes at other times). The reason it does this is partly, but not
wholly, historical and some things that used to work using this method (in
Win98 and earlier) no longer work in the same way (WinXP and later) because
of XP's restrictions on what a printer dialog can do with the printer
defaults, but nevetheless that's the way it still works. If this behaviour
of checking the default printer settings was "locked in" then when you wrote
code such as Printer.Orientation = vbPRORLandscape (which must of course be
done before you start printing the page) as soon as you started to print the
page VB would check the default printer settings and would "pick up" the
default printer orientation and it would use that orientation, effectively
rendering the Printer.Orientation property useless. That is one of the
reasons why a TrackDefault property is provided, and setting TrackDefault to
False immediately after setting Orientation fixes this orientation problem.
However, you do not actually need to explicitly set TrackDefault to False
because VB automatically does that for you whenever you set the Orientation
property. Therefore, don't assume that your original problem is not as I had
previously suggested simply because you cannot find a TrackDefault = False
line anywhere in your code, because TrackDefault = False will be implicitly
done by any Printer.Orienation setting.

Mike
Mike Williams
2007-09-06 18:38:34 UTC
Permalink
"Johan St�ck" <***@stack.se> wrote in message news:***@mid.individual.net...

. . . by the way, further to my previous response, this printer object
business must have you very worried for you to continue to attempt to
reproduce the problem. Your head must be so buzzing with it that I reckon
it's causing a Stäck overflow ;-)

[Sorry, couldn't resist that!]

Mike
MP
2007-09-06 19:04:05 UTC
Permalink
Post by Mike Williams
. . . by the way, further to my previous response, this printer object
business must have you very worried for you to continue to attempt to
reproduce the problem. Your head must be so buzzing with it that I reckon
it's causing a Stäck overflow ;-)
[Sorry, couldn't resist that!]
Mike
vbg!
I for one am glad :-)
needed a laugh right now!
Mike Williams
2007-09-11 22:19:34 UTC
Permalink
Post by Johan Stäck
Hello!
I have this VB6 application that prints on the designated default
printer. The program doesn't in itself have any functionality for
selecting a printer or doing printer setup. If no printer is found,
the program will inform the user about this, and all printing
functions are disabled. Some time ago I was installing the
program at a customer site and there was both a local printer
and a network printer, and there was a lot of "fiddling" with
printer drivers, network issues etc. It was all a mess. I
encountered a nasty bug (in the printer handling) in my own
program. The reason was that in some way I had managed
to create the situation where the PC running my program
"saw" only one printer, but this printer was *not* designated
as default printer. I.e. there was no default printer. Now, I
have tried to re-create this situation (one printer, *not* designated as
default), but I am not able to do it. Windows
seems always (quite logically) to designate a single remaining printer as
being default.
You haven't really given us a lot to go on, and you did say that there was
"a lot of fiddling with the printer drivers and network issues" at the time,
so it could be almost anything, but my guess is that you deleted (or
otherwise changed) the printer that the VB printer object was pointing to
while your VB app was running. Under certain circumstances this can cause
problems such as the one you describe.

For example, suppose that you have two printer drivers installed (PrinterA
and PrinterB) and that PrinterA is the system default printer at the time
you start your VB program. Also suppose that you have either deliberately or
accidentally set the VB Printer Object's PrinterDefault property to False,
causing it to fail to track the default printer. If you now use Control
Panel while your VB app is still running to change the system default to
PrinterB then VB will be left pointing to PrinterA, which is no longer the
system default printer. In fact VB will still be pointing to PrinterA even
if you delete PrinterA from your system. This of course will cause your
program to stop with an error as soon as it attempts to print something,
because the driver it is pointing to no longer exists. Anyway, in the
absence of further information from you, that would be my guess as to what
might have happened.

Mike
Microsoft Visual Basic MVP (deceased)
Pop`
2007-09-12 01:07:43 UTC
Permalink
Mike Williams wrote:
...
Post by Mike Williams
Mike
Microsoft Visual Basic MVP (deceased)
"deceased"? What does that mean? Only here in spirit or something? <g>
Mike Williams
2007-09-12 08:19:00 UTC
Permalink
Post by Pop`
Post by Mike Williams
Microsoft Visual Basic MVP (deceased)
"deceased"? What does that mean? Only here in spirit or something? <g>
Almost. I was slightly inebriated when I wrote it ;-) But don't worry. I'm
okay. It's just my MVP status that's deceased :-)

Mike
Jan Hyde (VB MVP)
2007-09-12 09:01:53 UTC
Permalink
"Mike Williams" <***@whiskyandCoke.com>'s wild thoughts
were released on Wed, 12 Sep 2007 09:19:00 +0100 bearing the
Post by Mike Williams
Post by Pop`
Post by Mike Williams
Microsoft Visual Basic MVP (deceased)
"deceased"? What does that mean? Only here in spirit or something? <g>
Almost. I was slightly inebriated when I wrote it ;-) But don't worry. I'm
okay. It's just my MVP status that's deceased :-)
Mike
When did that happen?
--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
Mike Williams
2007-09-12 15:23:32 UTC
Permalink
Post by Jan Hyde (VB MVP)
. . . but don't worry. I'm okay. It's just
my MVP status that's deceased :-)
Mike
When did that happen?
A few months ago, some time in June as I recall. The email notifying me of
the fact that I would not be reinstated this year was written in MicroSpeak®
but after careful decoding it became obvious that it was due to my various
rather outspoken postings on the newsgroup during the previous five or six
months regarding my dislike of the way that Microsoft have treated VB6
developers and the way they are effectively ripping off UK customers by
charging them up to $300 dollars more than they charge in America for a
virtually identical copy of Vista and apparently doing some sort of deal
with people like Amazon to prevent people in UK ordering a copy at the
United States price from the US Amazon web site. Looks like some rather
nasty and underhand goings on, there! Still, I would much rather lose my MVP
status than lose my self respect by sucking up to Micro$oft :-)

Mike
Karl E. Peterson
2007-09-12 21:08:21 UTC
Permalink
Post by Mike Williams
Post by Jan Hyde (VB MVP)
. . . but don't worry. I'm okay. It's just
my MVP status that's deceased :-)
Mike
When did that happen?
A few months ago, some time in June as I recall. The email notifying me of
the fact that I would not be reinstated this year was written in MicroSpeak®
but after careful decoding it became obvious that it was due to my various
rather outspoken postings on the newsgroup during the previous five or six
months regarding my dislike of the way that Microsoft have treated VB6
developers and the way they are effectively ripping off UK customers by
charging them up to $300 dollars more than they charge in America for a
virtually identical copy of Vista and apparently doing some sort of deal
with people like Amazon to prevent people in UK ordering a copy at the
United States price from the US Amazon web site. Looks like some rather
nasty and underhand goings on, there! Still, I would much rather lose my MVP
status than lose my self respect by sucking up to Micro$oft :-)
Ping me, offline.

(I'm assuming that's not a valid email address you're posting with? Mine is.)
--
.NET: It's About Trust!
http://vfred.mvps.org
Pop`
2007-09-12 14:24:34 UTC
Permalink
Post by Mike Williams
Post by Pop`
Post by Mike Williams
Microsoft Visual Basic MVP (deceased)
"deceased"? What does that mean? Only here in spirit or something?
<g>
Almost. I was slightly inebriated when I wrote it ;-) But don't
worry. I'm okay. It's just my MVP status that's deceased :-)
Mike
Ah, I see; gotta watch those darned "inebri" 's; sometimes they can be real
headaches and even a PIA. (double-entendre intended).
Looks like you're OK with whatever happened to the MVP status; that's
good. Spilt milk and all that.

Regards,

Pop`
Loading...