Visual Basic six and Transferring to Visual Basic.NET part IV
References for Programming
If they keep following points in mind before they upgrade the applications it will relieve the life of the programmers who want to upgrade their Visual Basic six applications. If they make some necessary changes in advance to their Visual Basic 6 application the upgrade process will definitely be smoother.
Few of the points to apply in Visual Basic six:
1. Arrays of Zero Bound
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. Visual Basic six supports arrays with lower bound even other than zero. You have to set the lower bound with LBound statement.
2. Windows APIs
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. As the underlying OS is the same, most of the API calls can be used in the same way. Also, APIs that support thread creation or windows subclassing can cause a problem in Visual Basic.NET.
3. Default Properties
If you specify default properties of the controls used in the code it will help smoother upgrade. 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 be unsuccessful.
4. Binding
Even though, 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.
See 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.
5. Dates
Use Date data type for storing dates because, unlike Visual Basic 6, Visual Basic.NET does not support double data type for storing dates.
Forms tasks changes in Visual Basic.NET
1. 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.
2. In Visual Basic .NET a GroupBox control is used instead of a Frame.
3. Unlike Visual Basic 6, the tab order can be set using the Tab Order from View menu in Visual Basic .NET.
4. 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.
5. In Visual Basic .NET, a controls collection used instead of a control array to iterate through the controls on the form.
6. 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.
All the best!