A.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. Here are the victims and their replacements . (We discuss the class library and CLR in Chapter 4 and Chapter 5.) A.2.1 ConstantsThe Microsoft.VisualBasic.Constants class in the Base Class Library defines a number of constants, such as the familiar vbCrLf constant, so these can be used as always. However, some constants, such as the color constants vbRed and vbBlue , are no longer directly supported. Indeed, the color constants are part of the System.Drawing namespace's Color structure, so they are accessed as follows : Me.BackColor = System.Drawing.Color.BlanchedAlmond In most cases, to access a particular constant that is not a field in the Microsoft. VisualBasic.Constants class, you must designate the enumeration (or structure) to which it belongs, along with the constant name . For example, the vbYes constant in VB 6 continues to exist as an intrinsic constant in VB.NET. However, it has a counterpart in the MsgBoxResult enumeration, which can be accessed as follows: If MsgBoxResult.Yes = MsgBox("OK to proceed?", ... For a list of all built-in constants and enums, see Appendix D. A.2.2 String FunctionsThe String function has been removed from the language. In its place, we simply declare a string and initialize it, using syntax such as: Dim str As New String("A"c, 5) which will define a string containing five A s. Note the use of the modifier c in "A"c to define a character (data type Char), as opposed to a String of length 1. This is discussed in more detail in Chapter 2. A.2.3 EmptinessIn VB 6, the Empty keyword indicates an uninitialized variable, and the Null keyword is used to indicate that a variable contains no valid data. VB.NET does not support either keyword, but uses the Nothing keyword in both of these cases. According to the documentation: " Null is still a reserved word in Visual Basic .NET 7.0, even though it has no syntactical use. This helps avoid confusion with its former meanings." Whatever. In addition, the IsEmpty function is not supported in VB.NET. A.2.4 Graphical FunctionalityThe System.Drawing namespace contains classes that implement graphical methods. For instance, the Graphics class contains methods such as DrawEllipse and DrawLine. As a result, the VB 6 Circle and Line methods have been dropped. Note that the VB 6 PSet and Scale methods are no longer supported and that there are no direct equivalents in the System.Drawing namespace. A.2.5 Mathematical FunctionalityMathematical functions are implemented as members of the Math class of the System namespace. Thus, the VB 6 math functions, such as the trigonometric functions, have been dropped. Instead, we can use statements such as: Math.Cos(1) Note also that the Round function has been replaced by the Round method of the System.Math class. A.2.6 DiagnosticsThe System.Diagonstics 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. A.2.7 MiscellaneousHere are a few additional changes to consider:
|