Results 1 to 3 of 3

Thread: converting vb6 to vb.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    14

    converting vb6 to vb.NET

    I am having trouble trying to convert some code to vb.NET. I know that in .NET there is no printer object. The problem I am having is having to do with printers.
    There is a component in system.windows.forms called printdocument but I am not sure how to use it in this code. I am trying to set the available printers. Here is the code:
    VB Code:
    1. '* Description..: This function sets the current printer from the printer list.      *
    2.     '*                                                                                   *
    3.     '*                Parameter     Description                                          *
    4.     '*                ----------    ---------------------------------------------------  *
    5.     '*                PrtName       Printer name                                         *
    6.     '*************************************************************************************
    7.  
    8.     Sub SetPrinter(ByRef PrtName As String)
    9.        
    10.         'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2068"'
    11.         Dim x As Printer
    12.        
    13.         On Error GoTo PrinterErr
    14.        
    15.         'UPGRADE_ISSUE: Printers collection was not upgraded. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2068"'
    16.         For Each x In Printers
    17.             'UPGRADE_ISSUE: Printer property x.DeviceName was not upgraded. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2069"'
    18.             If x.DeviceName = PrtName Then
    19.                 'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2068"'
    20.                 Printer = x
    21.                
    22.                 Exit For
    23.             End If
    24.         Next x
    25.        
    26.         Exit Sub
    27.        
    28. PrinterErr:
    29.        
    30.         MsgBox("Printer error has occurred.", MsgBoxStyle.Critical, "Printer Error: " & Err.Number)
    31.        
    32.     End Sub
    33.    
    34.     '*************************************************************************************
    35.     '* Function Name: PrintPos                                                           *                               *
    36.     '* Description..: This function prints text at the current x, y coordinates.         *
    37.     '*                                                                                   *
    38.     '*                Parameter     Description                                          *
    39.     '*                ----------    ---------------------------------------------------  *
    40.     '*                CurX          Current X printer position                           *
    41.     '*                CurY          Current Y printer position                           *
    42.     '*                CurText       Current Text to be printed on the printer            *
    43.     '*************************************************************************************
    44.    
    45.     Sub PrintPos(ByRef CurX As Integer, ByRef CurY As Integer, ByRef CurText As Object)
    46.        
    47.         'UPGRADE_ISSUE: Printer property Printer.CurrentX was not upgraded. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2069"'
    48.         Printer.CurrentX = CurX
    49.         'UPGRADE_ISSUE: Printer property Printer.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2069"'
    50.         Printer.CurrentY = CurY
    51.         'UPGRADE_WARNING: Couldn't resolve default property of object CurText. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
    52.         'UPGRADE_ISSUE: Printer object was not upgraded. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2068"'
    53.         'UPGRADE_ISSUE: Printer method Printer.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2069"'
    54.         Printer.Print(CurText)
    55.        
    56.     End Sub
    57. End Module

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: converting vb6 to vb.NET

    VB Code:
    1. Imports System.Drawing.Printing
    2.  
    3. Private Sub Form1_Load(ByVal sender As Object, ByVal e As _
    4.     System.EventArgs) Handles MyBase.Load
    5.     Dim pkInstalledPrinters As String
    6.  
    7.  
    8.     For Each pkInstalledPrinters In _
    9.         PrinterSettings.InstalledPrinters
    10.         cboInstalledPrinters.Items.Add(pkInstalledPrinters)
    11.     Next pkInstalledPrinters
    12.  
    13.  
    14.     cboInstalledPrinters.SelectedIndex = 0
    15. End Sub

    cboInstalledPrinters is a combobox.

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: converting vb6 to vb.NET

    the "On Error Goto" statement should be converted to Try/Catch error handling.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width