XML Code Commenting
XML code commenting was long supported in languages like C# and Java, and it is finally supported in this new release of Visual Basic.
|Figure 7. XML Comments: The figure shows inserted XML comments.|
XML code commenting allows you to use XML elements to document your code. To insert an XML comment, simply type three apostrophes before a class or method definition and the XML code templates will automatically be inserted for you (see Figure 7
Once you have documented your code with XML elements, an XML document containing all the comments in your code would be generated when you build your application. This XML document could then be processed by a third-party tool so that a help file may be generated. NDoc is one such tool that helps to generate documentations for .NET assemblies. For a detailed look at how to use NDoc to generate professional-looking documentation, checkout my MSDN article, "Generating Documentation for Your Visual Basic .NET Applications".
Besides the language innovations, the code editor in Visual Studio 2005 is also significantly improved to simplify Visual Basic development.
|Figure 8. Autocorrect: The figure shows how Autocorrect suggests remedies for an error.|
In Visual Studio .NET 2003, if a statement contains an error, the offending keyword within that statement would be highlighted, together with the reason for the error. In Visual Studio 2005, Microsoft has gone one step further with the Autocorrect feature.
The Autocorrect feature tries to analyze the cause of the error and make suggestions. For example, you may have remembered to add a reference to the System.Data.dll
for ADO.NET data access in your project, but have forgotten to import the System.Data namespace. In this case, if you try to declare a SqlDataReader variable, Visual Basic will flag the SqlDataReader class as not defined. Using Autocorrect, you can place your cursor over the underline and click the exclamation icon in red to view a list of suggested remedies (see Figure 8
|Figure 9. Exception Assistant: The figure shows the Exception Assistant in action.|
In this case, you can either use a fully qualified name for the SqlDataReader class, or simply add an imports statement at the top of the code.
Another improvement in Visual Studio is the new Exception Assistant. The Exception Assistant will kick into action when a runtime error occurs. For example, in Figure 9
I have forgotten to add the New
keyword to the instantiation statement, and using the Button object without instantiation will cause a runtime error. While this is a common error, it may take a Visual Studio .NET beginner a while to figure it out. The Exception Assistant tries to suggest ways to remedy the runtime error.