locked
The Printer Object RRS feed

  • Question

  • I am hoping to use a VB6 routine for printing in VB.NET 2008.  I have installed powerpack 3.0 as shown in the toolbox.
    I typed "Imports Microsoft.VisualBasic.Powerpacks.Printing.Compatability.VB6" above Public Class ...
    According to MSDN I need to declare the printer object. It gives example code: "Public Printer as New Printer" to put at the head of a procedure.
    VB rejects "Public" but will accept "Dim"  It rejects "Printer", the comment being 'Printer' is ambiguous in the namespace 'Microsoft.VisualBasic.Powerpacks.Printing.Compatability.VB6, referring to the Printer on the right.

    How should I declare the printer?

    Or is the claim that VB6 printer code can be used incorrect?

    South Pasadena
    Thursday, June 11, 2009 7:09 PM

Answers

  • Hi South,

    If you are declaring a Printer object at the Procedure level you can't use Public and must use Dim instead; if declaring it at the Class or Form level, you can use Public. If the docs are wrong on this, please let me know which topic it is and I'll make sure it gets corrected.

    As for the"ambiguous in Namespace" message, I think I've seen this before when you have more than one reference to the Power Packs - usually if you have Power Packs 3.0 installed on Visual Studio 2008 SP1, which shipped a newer verion of the .dll. Check your references and make sure that you are only referencing Microsoft.VisualBasic.PowerPacks.VS.

    Hope this helps,

    Steve Hoag Microsoft aka the V-Bee
    Friday, June 12, 2009 9:39 PM
    Moderator

All replies

  • Hi South,

    If you are declaring a Printer object at the Procedure level you can't use Public and must use Dim instead; if declaring it at the Class or Form level, you can use Public. If the docs are wrong on this, please let me know which topic it is and I'll make sure it gets corrected.

    As for the"ambiguous in Namespace" message, I think I've seen this before when you have more than one reference to the Power Packs - usually if you have Power Packs 3.0 installed on Visual Studio 2008 SP1, which shipped a newer verion of the .dll. Check your references and make sure that you are only referencing Microsoft.VisualBasic.PowerPacks.VS.

    Hope this helps,

    Steve Hoag Microsoft aka the V-Bee
    Friday, June 12, 2009 9:39 PM
    Moderator
  • Did you get your Printer class working?

    Where is the MSDN sample for how to set this up?

    I downloaded the latest VB power pak. I am using VS2008 SP1 and I have changed my project reference
    from:
    Microsoft.VisualBasic.Powerpacks.vs
    c:\Progam Files\Common Files\Microsoft Shared\ Visual Basic Power Packs\1.1\Microsoft.visualbasic.powerpacks.VS.dll

    to:
    Microsoft.VisualBasic.Powerpacks
    c:\Progam Files\Microsoft Visual Basic 2005 Power packs\3.0\Microsoft.visualbasic.powerpacks.dll

    Assuming the later is the latest because it is 3.0. This 3.0 is the one that has the printer object defined in it?????? Correct?

    I am upgrading a huge VB6 application to VS2008. This app uses the VB 6 printer object extensively. Th goal is to convert it
    to a .net win form app now and get a working version. Then later we will get the time to convert the app to a web page based app. So for now I just want to use the old VB printer object rather than do the .net rewrite.

    I have tried two approaches to defining the "printer object"

    ______________________________________________
    One: In my Globals.vb I defined it :

              Option Strict Off
              Option Explicit On
    Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
              Module globals_Renamed
               'The Globals Module
               '
               'Revisions:
                ' 4/17/03 Version 4.0.0
               Public Const REG_APP_NAME As String = "MyProject" 'used to determine which application root registry key to use
               'for app  settings - change this between major versions
               Const MODULE_NAME As String = "Globals"
      Public Printer As New Printer

    Result: all of my later usage resolves and the project compiles just fine. But during the first debug run I get:

    The Type initializer for 'MyProject.globals_renamed' threw an exception. MyProject 5

    OR if I move the declaration out of globals and into a function that uses it:

    Option Strict Off
    Option Explicit On
    Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
    Module FacesheetFunctions

        Private Const MODULE_NAME As String = "FacesheetFunctions"
        Private Const FONT_SIZE_DETAIL As Short = 9
        Private Const FONT_SIZE_HEADING As Short = 12
        Public Printer As New Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer

     

     

     

    Public Printer As New Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer


    Result:
    This compiles but even without any usage of the "printer" object in any line of code when I do the first debug run I get a popup box saying
    "Printer error. MicrosoftVisualBasic.PowerPacks.VS 482" on the first line in frm MDIMain that makes any reference to the above module.




    _____________________________________________
    Two:  I tried creating a Printer class:     (the code in Globals is now removed)

    Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
    Public Class Printer
        Public Printer As New Printer
    End Class

    Result: My use of the public object  in later functions do not resolve the reference.


    Friend Sub PrintBenefitSection(ByRef SectionTitle As String, ByRef objBenefits As colBenefits, ByRef BaseBenefit As String, ByRef CarrierID As String, ByRef ProgramID As String, ByRef StartX As Integer, ByRef startY As Integer)
            '**TO DO: Move to a report inside of VS2008 KC 5/7/2009
            ' 'prints a benefit section at the given X,Y location (printer coordinates)
            Dim i As Short
            Dim EndY, EndX, lMargin As Integer
            Dim strLastCarrProg As String
            lMargin = StartX
            Dim strDivider As String
            strDivider = "------- " & SectionTitle & " --------"
            'UPGRADE_ISSUE: Printer property 'Printer.CurrentX was not upgraded. Click for more: 'ms-help://MS.VSCC.2003                                                                                           /commoner/redir/redirect.htm?keyword="vbup2069"'
            printer.CurrentX = StartX

    Here I get an intellisense error that "CurrentX is not a member of MYProject.printer"

    _______________________________________________________

    So my question is how do I declare this so I can use it throughout the rest of the application. Do I need to declare it as its own new class or just import and dim it in each module???

    Thanks for the help.
    Tuesday, June 16, 2009 7:09 PM
  • Hi,

    If you are converting your application from VB6 using the Upgrade wizard, the wizard will insert the necessary code. Most of your printing code should just work without modification, however some things such as Printer code that used ScaleMode or other non-supported keywords may need to be rewritten.

    I don't remember specifically what the upgrade wizard does, but I believe it just declares a new instance of Printer in any procedure that used the VB6 Printer object.

    See the following Help topics for more info:
    http://msdn.microsoft.com/en-us/library/bb629239.aspx 
    http://msdn.microsoft.com/en-us/library/bb629226.aspx

    Hope this helps,
    Steve Hoag Microsoft aka the V-Bee
    Tuesday, June 16, 2009 10:28 PM
    Moderator
  • Thanks Steve,

    This app was first converted via VS2003 and then converted thru VS2008. Following the convert to VS2003, I believe the
    developer commented out all the      Printer."someproperty or method"      lines. Then he ran it thru the VS2008 and converted it a second time.   And those printer.... lines were commented.  That is where I entered the project to help engineer all the trouble spots that had been stubbed out.  They have since made alot of code changes so running thru the VS2008 convert wizard again may not be the right path. But I could get the post 2003 version or even the original VB6 version,  uncomment the printer... lines then covert that again with VS2008 and just look at functions and modules that have all the print lines to see what the VS2008 convert wizard did with them. That may be the example I need to see how it sets it up. And I could keep it away from their current VS2008 project, just using what I found as my guide to change their copy.   

    Thanks for the guidance. Ii has been 2 days since I found the new VB power paks and realized that someone already created the wrapper for the old VB6 "printer" object so I wont have to do it myself.  So far so good. 

    I will reply with our final resolution on "Printer" to add info to the fourm.

    Wednesday, June 17, 2009 12:32 AM