By Dan Mabbutt
Using the intrinsic VB.NET constants is a recommended programming practice. In the lesson introducing Chapter 5, I briefly mentioned that VB.NET provides constants that should be used whenever possible rather than your own variables since they're part of the VB.NET language and will be more easily understood and maintained. As Microsoft puts it on their web site:
Constants store values that remain constant throughout the execution of an application. They are meaningful names that take the place of a number or string and make code more readable.
Unfortunatly, the book commits that exact sin in an example when the Wrap variable in Step 10 of the example is created. The explanation of what the variable does and the data that is in it is excellent. The problem is that VB.NET already provides a constant that does the same thing called vbCrLf. An equivalent program could be coded this way. (Two other programming style changes I prefer are also subtituted. The shortcut operator described on page 150, &=, is used and the integer i is explicitly recast as a string even though VB.NET does it automatically in this case.)
Dim i As Integer For i = 1 To 10 TextBox1.Text &= "Line " & CStr(i) & vbCrLf Next i ~~~~~~~~~~~~~~~~~~~~~~~~~
To see what constants are available to your program, use the Object Browser in VB.NET. Here's the vbCrLF constant shown in the Object Browser.