No Printer Set in the running computer gaves NOE

It happened to me under Windows, and I cannot test that under MacOS (I installed a Printer / Set a default Printer on MacOS).

What happened to you when you use the code snippet (comes from the documentation) on a computer where no Default printer have been set ?

Here, it crash ayt the first attempt, but works fine on the second one (with my real code, not handly… but I save the settings “string” on disk, so…).

Var settings As String
Var p As PrinterSetup
p = New PrinterSetup
// Etc.

If it’s just a NilObjectException, catch it with a try-catch and then run the print routine again.


Thank you Greg.

So simple. Sometimes I wonder…

No, I am only a bit tired.

Right, but it would probably be yet better to not get this unexpected exception.

Yep, clearly a bug; and if a second try handles such condition ok, it seems some not initialized data that gets fixed (or get some wrong but kind of valid value) after the first try. Whatever is happening, Xojo must understand and fix.


Are you reusing some saved String of settings? Your above code does not show it, and such incomplete sample hinders more than helps, if so.

That clearly would be an user error. Xojo sadly makes it kind of hardware/platform dependent (it could be a JSON with properties handled by Xojo for each platform for example). And uninstalling printers, or reusing saved settings in different platforms surely will break things.

I thought you were getting a NOE using just those 3 lines. And that would be a bug.

As usual Rick is right.

NB: I implemented this 10 years ago. My user never complain (and he prints sometimes as I saw the papers on different printers / OS); he is not a power user (not able to search where the settings are saved to clear them…).