|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Insert Snippets Into Your Code (Visual Basic)
You can insert IntelliSense code snippets using the navigation tools in the Code Editor or by dragging files from Windows Explorer. When you know the name of the snippet you want to insert, you can do so by typing its shortcut followed by the TAB key. When you need to browse for an appropriate snippet, you can use the snippet picker, which gives you categorized lists of snippets to choose from.
After you insert the code snippet, you modify it to work in your application. For example, you may find that a particular snippet inserts a new method in your application. If you inserted this new method inside an existing method, you would need to delete some extra lines of code to fix the compiler errors. You might also want to change any messages to the user or file names found in the snippet. For more information, see.
To insert a snippet by browsing in the Code Editor
Right-click the Code Editor where you want to insert the code.
Click Insert Snippet on the shortcut menu. The IntelliSense code snippet picker appears.
As an alternative to steps 1 and 2, type a question mark followed by the TAB key in the Code Editor to open the code snippet picker.
Navigate to the task of your choice and click it. The snippet code is inserted into your code.
Once you have added the snippet to your code, there may be parts of it that need customization, such as replacing variable names with more appropriate names. The editor helps you with this process. For more information, see.
The snippets that appear in the picker are stored as files in subfolders of specific file locations. The file locations can be examined and changed using the. There is one file for each snippet, and the file-name extension for the files is .snippet. Snippets that you have created or acquired from another source can be stored anywhere in the file system, although they will not appear in the shortcut menu unless they reside in one of the specified folders. For more information, see snippet manager.
To insert a snippet when you know its shortcut
Type the shortcut for the snippet in the Code Editor followed by the TAB key. The snippet will be inserted.
Type the first few characters of the shortcut name for the snippet in the Code Editor, followed by a question mark and TAB. A picker will appear with the list of snippets whose shortcuts begin with the characters you typed. As you navigate the list, the title of the selected shortcut will appear as a ToolTip.
There are two ways to find the shortcut name for a code snippet:
Use theto view the shortcuts for all the snippets.
The shortcut is displayed as part of the description ToolTip in the code snippet picker.
To insert a snippet into your code using Windows Explorer
Open Windows Explorer.
Navigate in Windows Explorer to the folder that contains the file you want to insert. If you chose the default location for the installation of Visual Studio 2005, the snippets are stored in C:\Program Files\Microsoft Visual Studio 8\Vb. If you chose the default location for the installation of Visual Basic 2005 Express Edition, the snippets are stored in C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\VBExpress\Snippets\1033.
Drag the file from Windows Explorer to the place in your code where you want to insert it.