Click here to Skip to main content
Click here to Skip to main content

On Migrating a VB Project to VB.NET

By , 20 Aug 2004
 

Introduction

There will be certainly a need to migrate applications developed with VB6 to VB.NET. Although simple programs can be migrated without any rework as the present note shows, projects with any complexity may need rework and research. This may lead to the conclusion that it may be easier to start from scratch. The following features in VB projects are not supported in the VB.NET environment:

  • OLE Container Control
  • Dynamic Data Exchange (DDE)
  • DAO or RDO Data Binding
  • Visual Basic 5.0 Controls
  • DHTML Applications
  • ActiveX Documents
  • Property Pages

Migration Wizard Dialog

Visual Studio IDE has a menu item to bring up a wizard needed for migrating either VB or Java programs to .NET World. This can be accessed as shown. There also exists a way to convert VB code to VB.NET code which directly works with the code portion of the application. This helps to bring VB code to VB.NET, a small portion at a time instead of the whole project as in this note.

Clicking on Convert brings up the wizard as shown:

You can choose to convert either a VB or a Java application to be migrated to VB.NET. This is followed by the wizard explaining how this conversion will take place:

At this point, you will need to choose the project, *.vbp that you need to migrate, the Browse button may be used to bring in the project to the migration process. In this example, a very simple project called RevStr.vbp is being migrated.

The wizard can handle *.exe as well as *.dll type of projects. In the present case, it is a simple *.exe project.

In the next dialog, you need to select a location where your files can be located for the newly created VB.NET project. If you take the default, it will be created in a subdirectory of the project you are migrating, as in this case. Since it is creating a new directory, it will bring up a dialog to let you know that since the directory does not exist, it will create one as in the following screen:

This is all the information necessary for the upgrade. On clicking 'Next', the upgrade is made while you are watching the progress bar fill up.

Project Explorer and Solution Explorer

Whereas VB's Project Explorer had two forms with their code, the VB.NET migrated project has all the necessary class file references as shown here.

VB Project After Migration

Code Changes to Files

Original Code for one of the forms:

Function MyReverse(ByVal S As String, ByVal Size As Integer) As String
    Dim tmp As String: tmp = ""
    Dim i As Integer
    Dim x As Integer

    If (Len(S) Mod Size) <> 0 Then
        x = Len(S) Mod Size
        tmp = tmp & Right(S, x)
        S = Left(S, Len(S) - x)
    End If

    For i = 1 To (Len(S) \ Size)
        tmp = tmp & Right(S, Size)
        S = Left(S, Len(S) - Size)
    Next

    MyReverse = tmp
End Function

Private Sub Form_Load()
MsgBox (MyReverse("AXeBib", 3))
End Sub

Changed Code after Migration

Hey, VB.NET has lot more stuff than VB6!!

Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class Another
  Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
 Public Sub New()
  MyBase.New()
  If m_vb6FormDefInstance Is Nothing Then
    If m_InitializingDefInstance Then
       m_vb6FormDefInstance = Me
    Else
     Try 
      'For the start-up form, the first instance created is the
      'default instance.
      If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType _
                                   Is Me.GetType Then
        m_vb6FormDefInstance = Me
      End If
     Catch
     End Try
    End If
  End If
   'This call is required by the Windows Form Designer.
   InitializeComponent()
 End Sub
 'Form overrides dispose to clean up the component list.
 Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
  If Disposing Then
   If Not components Is Nothing Then
        components.Dispose()
   End If
  End If
  MyBase.Dispose(Disposing)
 End Sub
 'Required by the Windows Form Designer
 Private components As System.ComponentModel.IContainer
 Public ToolTip1 As System.Windows.Forms.ToolTip
 'NOTE: The following procedure is required by the Windows Form Designer
 'It can be modified using the Windows Form Designer.
 'Do not modify it using the code editor.
 <SYSTEM.DIAGNOSTICS.DEBUGGERSTEPTHROUGH()>
 Private Sub InitializeComponent()
   Dim resources As System.Resources.ResourceManager = New _ 
         System.Resources.ResourceManager(GetType(Another))
   Me.components = New System.ComponentModel.Container()
   Me.ToolTip1 = New System.Windows.Forms.ToolTip(components)
   Me.ToolTip1.Active = True
   Me.Text = "Form2"
   Me.ClientSize = New System.Drawing.Size(312, 206)
   Me.Location = New System.Drawing.Point(4, 30)
   Me.StartPosition = _
     System.Windows.Forms.FormStartPosition.WindowsDefaultLocation
   Me.Font = New System.Drawing.Font("Arial", 8!, _
             System.Drawing.FontStyle.Regular, _
             System.Drawing.GraphicsUnit.Point, _
             CType(0, Byte))
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.BackColor = System.Drawing.SystemColors.Control
   Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable
   Me.ControlBox = True
   Me.Enabled = True
   Me.KeyPreview = False
   Me.MaximizeBox = True
   Me.MinimizeBox = True
   Me.Cursor = System.Windows.Forms.Cursors.Default
   Me.RightToLeft = System.Windows.Forms.RightToLeft.No
   Me.ShowInTaskbar = True
   Me.HelpButton = False
   Me.WindowState = System.Windows.Forms.FormWindowState.Normal
   Me.Name = "Another"
 End Sub
#End Region 
#Region "Upgrade Support "
 Private Shared m_vb6FormDefInstance As Another
 Private Shared m_InitializingDefInstance As Boolean
 Public Shared Property DefInstance() As Another
   Get
     If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
       m_InitializingDefInstance = True
       m_vb6FormDefInstance = New Another()
       m_InitializingDefInstance = False
     End If
     DefInstance = m_vb6FormDefInstance
   End Get
   Set
       m_vb6FormDefInstance = Value
   End Set
 End Property
#End Region
'UPGRADE_NOTE: Size was upgraded to Size_Renamed. Click for more: 
'ms- help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1061"'
 Function MyReverse(ByVal S As String, ByVal Size_Renamed As Short) As String
   Dim tmp As String : tmp = ""
   Dim i As Short
   Dim x As Short

   If (Len(S) Mod Size_Renamed) <> 0 Then
     x = Len(S) Mod Size_Renamed
     tmp = tmp & VB.Right(S, x)
     S = VB.Left(S, Len(S) - x)
   End If

   For i = 1 To (Len(S) \ Size_Renamed)
     tmp = tmp & VB.Right(S, Size_Renamed)
     S = VB.Left(S, Len(S) - Size_Renamed)
   Next

   MyReverse = tmp
 End Function

 Private Sub Another_Load(ByVal eventSender As System.Object, _
    ByVal eventArgs As System.EventArgs) _
    Handles MyBase.Load
        MsgBox(MyReverse("AXeBib", 3))
 End Sub
End Class

Upgrade Report

Since it is anticipated that everything in VB may not go over to VB.NET, an upgrade report is also produced, which is a very nice thing. It also shows all the files and any facing issues in each of these files, as shown in the next and final screens. Besides some of the unsupported features mentioned in the beginning of this article, there will be other issues like graphics, Win32 APIs, legacy keywords etc.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

mysorian
Technical Writer Hodentek
United States United States
Member
Worked in the area of electrical discharges, high energy lasers, high voltage technology, plasma technology, lithography, thin film plastics, superconducting thin films, diamond thin films, electron accelerators, and free electron lasers for several years. Mentored/guided MS and PhD students at several universities in USA, Brazil, Australia, and India.
Reading books and photography are my hobbies.
 
Also trained workforce clients with legacy computer skills in web related technologies.
 
I recently authored a beginner level book on MS SQL Server Integration Services. Details available at the following link:
 
http://www.packtpub.com/sql-server-integration-services-visual-studio-2005/book
 
My second book was released in 2008
Learn SQL Server Reporting Services 2008
 
Get book details at the following site:
http://www.packtpub.com/learning-sql-server-2008-reporting-services/book
 
This is for anyone who is interested in Reporting Services a la Microsoft. It has over 50 hands-on exercises and covers all aspects of Reporting Services.
 
Recent new books:
 
Microsoft SQL Azure Enterprise Application Development 2010
-A Comprehensive book on SQL Azure
 
Microsoft Visual Studio LightSwitch Business Application Development 2011
A step-by-step approach that is sure to work

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 3memberNaveenSoftwares18 Oct '10 - 0:32 
Fine details. Would have been good if you have provided common errors that occurs after the conversion
GeneralRe: My vote of 3membermysorian18 Oct '10 - 4:03 
Thanks for writing to me. I really should have updated this article.
GeneralRetrieving COM class errormemberNaveenSoftwares18 Oct '10 - 0:29 
Hi,
When I converted a VB project to VB.NET project, I faced the following run-time error,
 
"retrieving the com class factory for component with clsid{xxxxx-xxx-...} failed due to the following error:800401584"
 
It occured in the place where the VB application was using dlls. It worked properly in the VB application but not in VB.NET.
 
Further i found the name of the dll was changed too. It was something like abcd.dll in VB, but after the conversion it was changed to interop.abcd.dll.
 
When I searched in google I found the following points related to this issue:
 
1) The Dll might not be registered --> But I registered the original version (abcd.dll) but could not register the converted verion (interop.abcd.dll)
 
2)The converted dll is just a wrap of original dll --> No idea
 
3)The dll is protected. --> Might be as I am woking a highly secured workstation
 
Whatever it may be, please give me a fine and exact solution to solve this issue
GeneralVB6 to C#.NetmemberMd. Ismail7 Jun '10 - 20:50 
How about VB6 to C#.Net conversion?
Is there any tool available from Microsoft?
Mi

GeneralRe: VB6 to C#.NetmemberNaveenSoftwares18 Oct '10 - 0:30 
No tool in microsoft. But available as third party applications
Generalvb6 to vb 2008 Excel Conversion problemmemberMember 44827428 Feb '10 - 19:43 
Hi friends,
I was create a project in vb6. this project purpose is integrate excel. now am converted in vb 2008. it working fine but form could not visible form status, after load excel this will show while working i could not view the form. how can i solve this problem. help me...
Generalerror in convertionmemberPremaP15 Jan '10 - 17:47 
hi,
 

i m using Visual Studio 2005,
as shown in the window, open project upgrade is not appearing
 
i m just opening the vb project in VB.net, atomatically it popsups the convertion window ,
rest all the steps are similar as u have indicated ,
 
but in the final step while converting it shows the following error .
 
what could be the problem,and what should i do to complete convertion . pls reply ASAP
 
unexpected exception occured during uprade engine operation. not able to bind the source (Exception fom HRESULT:0x80040000A(OLE_E_CANT_BIND SOURCE))
 

Thanks and Regards
Prema P
GeneralRe: error in convertionmembermysorian16 Jan '10 - 3:53 
Check if conversions are possible when OLE DB controls are used.Probably they are not supported.
GeneralExcel related application programmembervijayalaya11 Aug '09 - 22:46 
hi,
 
Am trying to convert an vb application which has several excel related functionallities into vb.net using the the method u gven.Even though it transfered the application successfully, i cant able to get the desired output lots of line throws runtime error.
 
Like the given below warning message the application has lots of warning messages in which some throws exception.
 
'UPGRADE_WARNING: CommonDialog property cmnDlg.FileTitle was upgraded to cmnDlg.FileName which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
 

Is there conversion of vb to vb.net is not including excel related code Confused | :confused: Clarify me mate.
 
Regards,
Vijay
GeneralRe: Excel related application programmembermysorian12 Aug '09 - 0:49 
Much has happened between the time this article was written and now. What does the upgrade report say? May be you should see if you can rectify those that throw exceptions and use the object browser and intellisense as much as possible
 
Good luck
GeneralRe: Excel related application programmembermysorian16 Jan '10 - 3:50 
The article considered a very simple example and it will be hard for me to suggest a fix for any other type. I need more specific information as to what you are converting. I believe each case may need a different kind of treatment depending on the source code/objects used in coding.
GeneralProblem in conversion of reportsmembercmrhema17 Mar '08 - 1:52 
I converted a vb 6.0 project in the above way, unfortunately the reports which were designed in active report designer(*.dsr) could not be converted.
 
Kindly let me know what to do.
 
regards
cmrhema
Generalproblem in conversionmemberSherrif15 Aug '06 - 1:14 
i am trying to convert a program in vb6 to vb .net, this program is connected to a database using DAO 6 control. This control is not available in vb.net, so it is not converting the program vb.net.
 
how should i solve this problem?
 
usman
GeneralRe: problem in conversionmembermysorian15 Aug '06 - 3:57 
Dear Usman:
 
You may have to add a reference to your project the Microsoft DAO 3.6 library in VS 2005 and take it from there. The final prodcut may not look nice and tidy. If your applcaition is samll, I suggest you start with a clean slate.
 
Good luck,
 
Jayaram Krishnaswamy
Generalexperience with ...memberSpeedySpeedy20 Aug '04 - 0:58 
A few month before I tried to convert a Project from VB6 to VB .NET with the wizard.
It made no sense, after one day with the wizard and five days trying to sort the bugs out
I gave up.
Then I've written the program completely new in VB.NET. Now the Program works and it is better structured. (No modules any more, only classes)
Maybe there might be programs where the wizard makes sense, I don't now. I don't think so.
 

GeneralRe: experience with ...membermysorian20 Aug '04 - 4:06 
I have very limited experience with migration, but it appears that the migration is not easy except for the very simplest of the programs. Microsoft does this too often. When you have started programming in VB.Net 2003, Microsoft is already going ahead with pushing VB.Net 2005. There appears to be no breathing space.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 21 Aug 2004
Article Copyright 2004 by mysorian
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid