Datasheet
This capability to fully integrate the template supporting the expanded code with the highlighted elements,
helping you navigate to the items you need to edit, makes code expansion such a valuable tool.
Code Snippets
You can, with a click of your mouse, browse a library of code blocks, which, as with code expansion,
you can insert into your source fi le. However, unlike code expansion, these snippets aren ’ t triggered by a
keyword. Instead, you right - click and (as shown in Figure 1 - 20) select Insert Snippet from the context menu.
This starts the selection process for whatever code you want to insert.
FIGURE 1 - 20
The snippet library, which is installed with Visual Studio, is fully expandable, as discussed later in this chapter.
Snippets are categorized by the function on which each is focused. For example, all the code you can reach via
code expansion is also available as snippets, but snippets go well beyond that list. There are snippet blocks for
XML - related actions, for operating system interface code, for items related to Windows Forms, and, of course,
a lot of data - access - related blocks. Unlike code expansion, which enhances the language in a way similar to
IntelliSense, code snippets are blocks of code focused on functions developers often write from scratch.
As shown in Figure 1 - 21, the insertion of a snippet triggers the creation of a placeholder tag and a context
window showing the categories of snippets. Each of the folders can contain a combination of snippet fi les or
subdirectories containing still more snippet fi les. Visual Basic 2010 Express contains a subset of the folders
provided with Visual Studio 2010. In addition, Visual Studio includes the folder My Code Snippets, to
which you can add your own custom snippet fi les.
Selecting a folder enables you to select from one of its subfolders or a snippet fi le. Once you select the
snippet of interest, Visual Studio inserts the associated code into your source fi le. Figure 1 - 22 shows
the result of adding an operating system snippet to some sample code. The selected snippet was
Windows ➪
Event Logs ➪ Read Entries Created by a Particular Application from the Event Log , which
isn ’ t included with Visual Basic 2010 Express, although the code is still valid.
Project ProVB_VS2010
❘
37
CH001.indd 37CH001.indd 37 4/5/10 11:56:51 AM4/5/10 11:56:51 AM