Auto Correct Smart Tags

In the same way that Word places squiggles under errors in grammar or spelling, Visual Studio uses squiggles to indicate errors in code. When a word in your code is marked with a squiggle, you can view more information by holding your mouse cursor over the word to display a tool tip, or you can view the information in the Error List window in Visual Studio. If multiple errors exist, you can click the entry in the error list to move directly to the problem code.

The squiggles come in a variety of colors; each represents a different kind of error or potential problem.

• Red squiggles indicate that your code contains a syntax error. After you correct the syntax error, the squiggle disappears.

• Blue squiggles indicate that your code contains semantic errors. For example, if you misspell the name of a class, the class name will have a blue squiggle under it until you've fixed the error. Visual Studio even provides smart tags with suggestions for fixing the code, as shown earlier in Figure 2.23.

• Green squiggles indicate warnings. For example, if you've declared a variable in your code but have not made any assignment to it, Visual Studio flags the variable with a green squiggle to indicate that there is an unused variable.

• Purple squiggles indicate new errors in code that you've written while in break mode (discussed later in this chapter under the heading Edit and Continue).

When you hold your mouse cursor over a blue-squiggled word, a smart tag panel gives you additional information and presents a way to fix the error quickly. These smart tag panels in Visual Studio are very similar to the smart tags in Word and Excel. They provide an action that you can perform on the erroneous text. When you click the smart tag panel, you can open the Error Correction Options window to select from a list of correction options. In Figure 2.26, the Error Correction Options window displays information about why the error occurred and provides a way to fix it. In this example, you can click the Change 'Strin' to 'String' link and the code is fixed in the Code Editor.

Dim myString As Strin = "Test"

Change 'Strin' to 'String'.

Figure 2.26. Error Correction Options window

+1 0

Post a comment