On Migrating a VB Project to VB.NET





4.00/5 (10 votes)
Aug 16, 2004
3 min read

211586
Describes the migration of a simple VB project to VB.NET.
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.