1. Home
  2. Computing & Technology
  3. Visual Basic

By , About.com Guide

* Code Snippets

Visual Basic 2003 provided a neat trick of saving little chunks of code in the Toolbox. If you attended any Microsoft training, you probably saw this trick because the instructors would use it constantly to save time. (And sometimes the Microsoft technies made things look waaaay easier than they really were. "Let me insert this code that a whole team puzzled over for six months. There! ... Wasn't that easy!") You can still do this in Visual Basic 2005, but they added a whole new way called Code Snippets.

Code snippets let you customize the auto-complete logic in Visual Studio with your own shortcuts. A code snippet is defined with XML files. This gives you the ability to not only insert some handy code, but also include values that change with the code context or you can enter part of the code on the spot. Entering a snippet is simplicity itself. Just right-click your code window where you want the snippet inserted and select Insert Snippet or type the code snippet's shortcut and hit the Tab key.

The good news is that Visual Studio 2005 comes with a really good library of code snippets "out of the box". The illustration below shows you just the categories of snippets you get.

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

The better news is that Microsoft has also created some great tools to help you get the most from these snippets. Visual Studio 2005 comes standard with the Code Snippet Manager directly under the Tools menu. The main dialog window is shown below.

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

In addition, you can download the Code Snippet Editor for Visual Basic 2005 from Microsoft. Since code snippets are actually saved in XML (the XML source for one is shown below), updating them in native mode can be a challenge. This tool gives you an editor designed just for that job. See the illustration.

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

The very best news is that the code snippet idea is so good, a whole mini-industry has popped into existence that can save you gobs of time. Just search the web for "Visual Basic Code Snippet" to find a lot of sites that specialize in making just code snippets available to you.

VB.NET 2005 seems to have finally created a world of reusable code!

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. What's New in Visual Basic 2005!

©2009 About.com, a part of The New York Times Company.

All rights reserved.