D.2. Changes to Programming ElementsVB.NET has removed support for several programming elements because the underlying .NET Framework Class Library and the Common Language Runtime (CLR) contain equivalent functionality. Other syntax and usage changes have been made as well. D.2.1. ConstantsMany predefined constants available in VB 6, such as the familiar vbCrLf constant, are now part of VB.NET's Microsoft.VisualBasic.Constants class. They can be used in VB.NET just as they were used in VB 6. However, some constants, such as the color constants vbRed and vbBlue, are no longer directly supported. The color constants are part of the System.Drawing namespace's Color structure and are accessed as follows: Me.BackColor = System.Drawing.Color.BlanchedAlmond When using most constants, other than those in the Microsoft.VisualBasic.Constants class, you will need to include some or all of their namespace and class name prefix. For example, the vbYes constant in VB 6 continues to exist in VB.NET as a member of the MsgBoxResult enumeration. It can be used as follows: If (MsgBoxResult.Yes = MsgBox("OK to proceed?", ... For a list of built-in constants and enumerations, see Appendix C. D.2.2. String FunctionsThe String function has been removed from VB.NET. Its functionality now appears as part of the String data-type constructor. Dim giveThemAnA As New String("A"c, 5) which defines a string containing five As. The c modifier in "A"c indicates a character literal (data type Char) as opposed to a standard one-character string (data type String). D.2.3. EmptinessIn VB 6, the Empty keyword indicated an uninitialized variable, and the Null keyword was used when a variable contained no valid data. VB.NET does not support either keyword but uses the Nothing keyword in both of these cases. The Null keyword continues to be a reserved word in VB.NET, but it has no functionality. The IsEmpty function is no longer supported in VB.NET; use the IsNothing function instead. D.2.4. Graphical FunctionalityThe System.Drawing namespace contains classes that implement graphical methods. Its Graphics class contains methods such as DrawEllipse and DrawLine. As a result, the VB 6 Circle and Line methods, associated with Forms and other drawing surfaces, have been removed. VB 6's PSet and Scale methods are no longer supported, and they have no direct equivalents in the System.Drawing namespace. D.2.5. Mathematical FunctionalityMathematical functions are implemented as members of .NET's System.Math class. All VB 6 math functions, such as the trigonometric functions, have been dropped from the VB.NET language itself, replaced with members of System.Math. Typical using is: result = Math.Cos(1) The Round function has been replaced by the Round method of the System.Math class. D.2.6. DiagnosticsThe System.Diagnostics namespace provides classes related to programming diagnostics. Most notably, the VB 6 Debug object is gone, but its functionality is implemented in the System.Diagnostics.Debug class, which has methods such as Write, WriteLine (replacing Print), WriteIf, and WriteLineIf. D.2.7. MiscellaneousHere are a few additional changes to consider.
|