- First thing you must do is to Convert earlier version of VB code to VB6 .
- Add "Option Explicit" to all VB code behind forms. Because VB.NET does not support a variable declaration without a type declaration. So do not leave any variable declaration types as default variant type.
- Just keep in mind that all the controls in VB.NET are objects.
- Clean the multiple variable declarations per line. All variable declarations should be in deferent lines.
- Do not use (0 – Zero) to disable the timer, instead set Timer enabled = false.
- Make sure the code compile and runs before the conversion.
- Convert all arrays to Zero based.
- Migrate all your Data access code from DAO and RDO to ADO.
- Do not use defaults when accessing control properties. Change code that is using Text1 to read the text box value because Text1 in VB.NET represents textbox object.
- Rename any VB.NET keywords in the VB6 code.
- Form.Print doesn't exist in VB.NET
- Another feature missing from VB.NET is control arrays.
- VB6 is a 16-bit integer; in VB.NET, it is a 32-bit integer. The 16-bit equivalent in .NET is a Short,
- VB.NET requires a managed RCW class to wrap every ActiveX control or COM component it needs to use. Thankfully, the Upgrade Wizard creates these assemblies automatically, and modifies the imported code to use them.
- The ZOrder propertyis missing in VB.NET , the wizard will convert it, but add a message that the behavior has changed.
- An Integer in VB6 is a 16-bit integer; in VB.NET, it is a 32-bit integer. The 16-bit equivalent in .NET is a Short
In .NET, control arrays aren't needed to handle multiple events. Instead, you can use the handles clause or the AddHandler statement to link up as many controls as you want to a single event handler. You can then use the sender parameter to interact with the control that fires the event.VB.NET code:
Private Sub Highlight(sender As _ Object, e As MouseEventArgs) _
Handles lblLine1.MouseMove, _ lblLine2.MouseMove
Dim lbl As Label = _ CType(sender, Label)
lbl.ForeColor = _ Color.RoyalBlue
Big change in Popup Menu'sIn classic VB you usually creates munu object and use built-in PopupMenu command to activate it:
VB 6 code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
In VB.NET, you can't use the same menu for a main menu and a context menu. Instead, you'll need to create a new ContextMenu object, and copy the ordinary menu information into it with the CloneMenu() method:VB .NET code:
Dim mnuPopUp As New ContextMenu()
Dim mnuItem As MenuItem
Private Sub Form1_MouseDown (ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button = Mouse _ Buttons.Right Then
Me.ContextMenu.Show(Me, _ New Point(e.X, e.Y))
- An Internet project using Web Classes, ActiveX Documents, or DHTML: None of these development technologies is supported in .NET.
- A database project that uses data binding to other controls: These features can be upgraded under some circumstances, but will definitely fail with the DAO and RDO data access technologies.
- An ActiveX control or ActiveX DLL project: While you can create .NET equivalents of these COM-based types of programs, you will lose all of their existing COM features. If you have controls or components that are still being shared among numerous applications, it will probably be easier to use them in .NET or to make additional .NET versions, rather than trying to migrate them and replace the originals.
- ADO and ADO.NET objects models are totally different. Although it is certainly possible to use ADO within your Visual Basic .NET application, your mileage will vary as far as performance is concern. It is possible to preserve your existing investment in ADO while still taking advantage of .NET controls and performing such tasks as data binding and marshaling Recordsets through XML Web services.
The classic ADO Recordset functionality has been split into smaller and more specialized objects: the DataSet and DataReader classes. Forward-only "firehose" Recordsets map directly to DataReaders, while disconnected Recordsets map best to DataSets. In essence, a DataSet contains collections of DataTables and DataRelations. The DataTable class conceptually corresponds closely to a database table, while the DataRelation class is used to specify relations between the DataTables.
- Following is the simple to convert your ADO RecordSet object to VB.NET DataTable object using OleDBDataAdaptor.
Dim olead As New Data.OleDb.OleDbDataAdapter()
Dim dt As New Data.DataTable()
'We use the DataAdapter to fill a DataTable
'Now we bind the DataTable to the DataGrid
Me.DataGrid1.DataSource = dt
'This is cleanup. Always close your objects as soon as you are done with them.
- Calling classic VB COM components (unmanaged code libraries) from .NET managed code is known as a Runtime-Callable Wrapper. See the corresponding posting for more details.
- Notice the changes happened to ADO Command object METHODS.
- ExecuteReader : Execute a query and return a DataReader object.
- ExecuteScalar : Execute a query and return a single value.
- ExecuteXmlReader : Execute an XML query and return an Xml- Reader object.
- ExecuteNonQuery : Execute a query with no results