Printers.count - runtime

I have a project that's using the printing power pack. I'm getting a runtime when calling the printers.count method when no printers have been installed. Has anyone encountered this problem

John



Answer this question

Printers.count - runtime

  • cgirolami

    Here is the exception error: I did a test on my development box at work. Had 1 printer installed works I removed the printer and the folling error occurs.

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.Exception: Printer error.
    at Microsoft.VisualBasic.ErrObject.Raise(Int32 Number, Object Source, Object Description, Object HelpFile, Object HelpContext)
    at Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.PrinterObject.GetDefaultPrinterName()
    at Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer..ctor()
    at PrintersCount.Form1.Button1_Click(Object sender, EventArgs e) in d:\Testing\PrintersCount\PrintersCount\Form1.vb:line 5
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    PrintersCount
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/Testing/PrintersCount/PrintersCount/bin/Debug/PrintersCount.exe
    ----------------------------------------
    Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
    ----------------------------------------
    System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------
    System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
    ----------------------------------------
    Microsoft.VisualBasic.PowerPacks.Printing.Printer
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.61208.0
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic.PowerPacks.Printing.Printer/1.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.PowerPacks.Printing.Printer.dll
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
    <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.



  • Codigo47

    Your code works fine for me. What is the specific error message that you are seeing

  • LoveWinXP

    Here is the code:

    Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim printer As New Printer

    If Printers.Count > 0 Then

    MsgBox(Printers.Count)

    End If

    End Sub

    End Class


  • nunodonato

    John -

    Jeff is correct; Windows 2000 isn't officially supported. It should work, however, if you make sure that there is a valid default printer before creating a new printer object:

    Old Code:

    Dim printer As New Printer

    If Printers.Count > 0 Then

    MsgBox(Printers.Count)

    End If

    New Code:

    If Printers.Count > 0 Then

    Dim printer As New Printer

    MsgBox(Printers.Count)

    End If

    Hope this helps,

    Steve



  • frappy666

    Yes, you are right. This PowerPacks Printer library only works on machines of XP and above. Thanks.

  • user32

    Hi John,

    I just tried this on a machine with no printers and Count is returning 0 as expected. Can you share the code that is triggering the runtime error

    Steve Hoag

    Visual Basic Power Packs



  • aliassce

    I dont remmber what the error is I'll post it on monday morning. I ran the code at home without any problems. My test computer is running Windows 2000 sp4 and my computer at home is XP sp2 maybe its a problem win windows 2000.

    john


  • M.Glenn

    where do I get the power pack

    how is it installed


  • Printers.count - runtime