Write Readable Code and Comments for Windows Forms Applications
(Page 1 of 4 )
In this second part of a five-part series that shows you how to code and test a Windows Forms application, you will learn (among other things) how to make sure your code and comments are clear and readable. This will simplify the debugging process and in general make code maintenance much easier. This article is excerpted from chapter 3 of
Murach's Visual Basic 2008, written by Anne Boehm (Murach, 2008; ISBN: 1890774456).
How IntelliSense helps you enter the code for a form
In figure 3-2, you saw how IntelliSense displays a list of the available members for a class or an object. IntelliSense can also help you select a type for the variables you declare, which you’ll learn how to do in chapter 4. And it can help you use the correct syntax to call a procedure as shown in chapter 6 or to call a method as shown in chapter 11.
With Visual Basic 2008, IntelliSense has been improved to help you even more as you enter the basic code for an application. In particular, IntelliSense can help you enter statements and functions as well as the names of variables, objects, and classes. Figure 3-5 illustrates how this works.
The first example in this figure shows the list that IntelliSense displays when you start to enter a new line of code. Here, because I entered the letter d, the list includes only those items that start with that letter. As described earlier in this chapter, you can enter as many letters as you want, and Visual Studio will continue to filter the list so it contains only the items that begin with those letters. You can also scroll through the list to select an item, and you can press the Tab or Enter key to insert the item into your code.
Note that when you select a keyword that begins a statement, a description of the statement is displayed in a tool tip along with the syntax of the statement. That can help you enter the statement correctly. In addition, as you enter the statement, you’re prompted for any additional keywords that are required by the statement.
The second example in this figure shows the list that’s displayed as you enter the code for an If statement. You’ll learn more about this statement in chapter 5. For now, just notice that after I typed a space and the letter t following the If keyword, Visual Studio displayed a list of all the items that begin with the letter T. That made it easy to select the item I wanted, which in this case was the name of a control.
If you’ve used previous versions of Visual Basic, you’ll appreciate these expanded IntelliSense features. For example, it’s easy to forget the exact syntax of a statement or function, so the tool tip that’s displayed when you select a statement or function can help refresh your memory. Similarly, it’s easy to forget the names you’ve given to items such as controls and variables, so the list that’s displayed can help you locate the appropriate name. And that can help you avoid introducing errors into your code.
Although it’s not shown here, Visual Basic 2008 IntelliSense also lets you see the code that’s behind a list while the list is still displayed. To do that, you simply press the Ctrl key and the list becomes semi-transparent. This eliminates the frustration a lot of programmers felt when code was hidden by an IntelliSense list in previous versions of Visual Studio.
The list that’s displayed when you enter a letter at the beginning of a line of code

The list that’s displayed as you enter code within a statement

Description
The IntelliSense that’s provided for Visual Basic 2008 lists keywords, functions, variables, objects, and classes as you type so you can enter them correctly.
When you highlight an item in a list, a tool tip is displayed with information about the item.
If you need to see the code behind a list without closing the list, press the Ctrl key. Then, the list becomes semi-transparent.
Figure 3-5. How IntelliSense helps you enter the code for a form
Next: The event handlers for the Invoice Total form >>
More Visual Basic.NET Articles
More By Murach Publishing
|
This article is excerpted from chapter three of Murach's Visual Basic 2008, written by Anne Boehm (Murach, 2008; ISBN: 1890774456). Check it out today at your favorite bookstore. Buy this book now.
|
|