Correcting Code in a Windows Forms Application
(Page 1 of 4 )
Welcome to the third part of a five-part article series on how to code and test a Windows Forms application. In this article you will learn a number of useful ways to deal with code, such as how to correct syntax errors, how to use code snippets, and so forth. This article is excerpted from chapter three of
Murach's Visual Basic 2008, written by Anne Boehm (Murach, 2008; ISBN: 1890774456).
How to detect and correct syntax errors
As you enter code, Visual Studio checks the syntax of each statement. If a syntax error, or build error, is detected, Visual Studio displays a wavy line under the code in the Code Editor. In the Code Editor in figure 3-9, for example, you can see wavy lines under three different portions of code. Then, if you place the mouse pointer over one of the errors, Visual Basic will display a description of the error.
If the Error List window is open as shown in this figure, any errors that Visual Studio detects are also displayed in that window. Then, you can double-click on an error message to jump to the related code in the Code Editor. After you correct a coding problem, its message is removed from the Error List window.
If the Error List window isn’t open, you can display it by selecting the Error List command from the View menu. When you’re learning Visual Basic, you’re going to make a lot of coding errors, so it makes sense to keep this window open. But after you get used to Visual Basic, you can conserve screen space by using the Auto Hide button so this window is only displayed when you point to the Error List tab.
By the way, Visual Studio isn’t able to detect all syntax errors as you enter code. So some syntax errors aren’t detected until the project is built. You’ll learn more about building projects later in this chapter.
The Code Editor and Error List windows with syntax errors displayed

Description
Visual Studio checks the syntax of your Visual Basic code as you enter it. If a syntax error (or build error) is detected, it’s highlighted with a wavy underline in the Code Editor, and you can place the mouse pointer over it to display a description of the error.
If the Error List window is open, all of the build errors are listed in that window. Then, you can double-click on any error in the list to take you to its location in the Code Editor. When you correct the error, it’s removed from the error list.
If the Error List window isn’t open, you can display it by selecting the Error List command from the View menu.
Visual Studio doesn’t detect some syntax errors until the project is built. As a result, you may encounter more syntax errors when you build and run the project.
Figure 3-9. How to detect and correct syntax errors
Next: Other skills for working with code >>
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.
|
|