Datasheet

As you can see, this code snippet is specifi c to reading the Application Log. This snippet is useful because
many applications log their errors to the Event Log so that they can be reviewed either locally or from another
machine in the local domain. The key, however, is that the snippet has pulled in the necessary class references,
many of which might not be familiar to you, and has placed them in context. This reduces not only the time
spent typing this code, but also the time spent recalling exactly which classes need to be referenced and which
methods need to be called and customized.
Finally, it is also possible to shortcut the menu tree. Speci cally, if you know the shortcut for a snippet, you
can type that and then press Tab to have Visual Studio insert the snippet. For example, typing evReadApp
followed by pressing Tab will insert the same snippet shown in Figure 1 - 22.
Tools such as code snippets and especially code expansion are even more valuable when you work in
multiple languages. Keep in mind, however, that Visual Studio isn t limited to the features that come in the
box. It s possible to extend Visual Studio not only with additional controls and project templates, but also
with additional editing features.
Additional Components for Visual Studio
You might be interested in two additional tools that work with Visual Studio. Even better, both are free.
The fi rst is a tool for creating your own Visual Basic snippets. As discussed, snippets can be powerful tools
when you need to replicate relatively small but commonly used blocks of code that will be customized.
While Visual Studio ships with several such snippets, Microsoft probably hasn t included the snippet you
want the most.
This is where the rst tool comes in: a Snippet Editor for Visual Basic code snippets. This editor doesn t
actually live within Visual Studio; it just updates the snippet fi les you want to use from Visual Studio.
Behind the scenes, snippets are actually XML fi les with embedded text that represents the code used in the
snippet. What the Snippet Editor does is read that XML and interpret all of the embedded logic related to
things such as replacement blocks. This tool makes it possible for Visual Basic developers to create custom
snippets without worrying about the XML formatting details. It is available from MSDN at
http://msdn2
.microsoft.com/en-us/vbasic/ms789085.aspx .
The second tool is a true add - in to Visual Basic. When Microsoft was announcing features for .NET 2.0,
it was apparent that Visual Basic and C# had different feature lists. Over time, the developers in each
community started to better understand what these features represented, and in many cases demanded their
inclusion. One such feature was native support in C# for refactoring, the capability to modify a variable
name for example, to take i and call it loopControl so that it s more readable. Modifying code to
improve structure, performance, and maintainability is referred to generically as refactoring .
Traditionally, such changes might make the code more maintainable but it often entailed more risk than
reward; as a result they seldom were made. The problem, of course, is that a human tends to miss that one
remaining reference to the old version of that method or variable name. More important, it was a time -
consuming task to fi nd all of the correct references. Fortunately, the compiler knows where these are, and
that s the idea behind automated refactoring: You tell Visual Studio what you want to change and it goes
through your code and makes all the necessary changes, using the same rules the compiler uses to compile
your code.
This is a great maintenance tool; unfortunately, by the time most Visual Basic developers understood
what it implied, it was too late for the Visual Basic team to implement a solution in Visual Studio 2005.
However, the team did do better than just say, So sad, too bad. They found a commercial product
that actually had more features than what the C# team was developing from scratch. Then they bought
a license for every Visual Studio developer, allowing free download of the tool. This solution worked so
well for everyone involved that they chose to continue it in Visual Studio 2008 and Visual Studio 2010.
With refactoring, you can quickly clean up gnarly, hard - to - read code and turn it into well - structured logic
that s much more maintainable. The free version of the refactoring tool is available at
www.devexpress
.com/Products/NET/IDETools/VBRefactor/ .
Project ProVB_VS2010
39
CH001.indd 39CH001.indd 39 4/5/10 11:56:53 AM4/5/10 11:56:53 AM