Those already familiar with Visual Basic shouldn't have to worry about migrating to Visual Basic.NET. In this article Vaijayantee shows us how to upgrade our existing applications to Visual Basic.NET, different .NET variable types, and her own personal programming recommendations. After reading this article you'll be able to migrate from VB6 to VB.NET in no time!
Migrating to Visual Basic.NET from Visual Basic 6 - Programming Recommendations (Page 5 of 7 )
In general, it will ease the life of the programmers who want to upgrade their Visual Basic 6 applications, if they keep following points in mind before they upgrade the applications. If they make some necessary changes in advance to their Visual Basic 6 application the upgrade process will definitely be smoother. Let us just go through some of the points that will help application your applications in Visual Basic 6 smoothly
Though both, Visual Basic 6 as well as Visual Basic.NET support late binding, it can cause problems in upgrade process when resolving default problems. In such cases, it is better to re-write the code using early binding
Let us examine the code written Visual Basic 6 using late binding.
Dim ObjLbl as Object
Set ObjLbl = Me.Label1
ObjLbl.Caption = "Hello"
This code works fine with Visual Basic 6. But, when we try to upgrade it to Visual Basic.NET, the caption property of a Label needs to be changed to Text property. The ObjLbl is type-less and the wizard has no way of knowing what properties it is supposed to change. If you change the first line of the code to “Dim ObjLbl as Label” then the code upgrades just fine.
Another thing to remember is the Date data type. We should use Date data type for storing dates because, unlike Visual Basic 6, Visual Basic.NET does not support double data type for storing dates.
It will help smoother upgrade if you specify default properties of the controls used in the code. In the above-mentioned code, using ObjLbl.Caption=”Hello” instead of using just ObjLbl = “Hello” will help the wizard in resolving the default property. Though the wizard will try to find out the default properties, it will not be always be successful. Again late bound default properties will inevitably fail.
Zero Bound Arrays
Visual Basic 6 supports arrays with lower bound even other than zero. You have to set the lower bound with LBound statement. When an application with array other than zero is upgraded, the Upgrade Wizard issues an UPGRADE_WARNING saying that the array is converted to LBound zero.
As the underlying OS is the same, most of the API calls can be used in the same way. Some data types like Long are different than the Visual Basic 6 though here the Upgrade Wizard can take care of the changes. In some cases like Fixed Length Strings that Visual Basic.NET does not inherently support, can cause a problem for the Upgrade Wizard. Also, APIs that support thread creation or windows subclassing can cause a problem in Visual Basic.NET
Considerations for Forms and Controls
In general, we can say that keeping following changes in mind will help us in upgrading the Visual Basic 6 projects.
Forms tasks changes in Visual Basic.NET
Unlike Visual Basic 6, the tab order can be set using the Tab Order from View menu in Visual Basic .NET
Determining modifier keys for mouse and keyboard events is very different from Visual Basic 6. We have to find out value of the key using the keys enumeration and compare it to the class’s modifier method.
When we are aligning and sizing a control in Visual Basic 6, the last control in selection is the reference whereas in Visual Basic .NET it is the first control
For deciding the runtime position of the Form, Visual Basic 6 uses Startup property while Visual Basic .NET uses StartPosition property. Also, instead of Left and Top properties, Visual Basic.NET uses Location property by setting it to a point object
In Visual Basic .NET a GroupBox control is used instead of a Frame
In Visual Basic .NET, a controls collection used instead of a control array to iterate through the controls on the form.