DevCity.NET -
Using the “Code Snippet Editor for Visual Basic 2005”
Dave Barr
Not much to tell, so for now view some of my custom logo designs, and a photograph of mine that made it to the local newspaper. 
by Dave Barr
Published on 5/24/2006

This is a short and very basic tutorial about using the very powerful, yet easy-to-use FREE "Code Snippet Editor for Visual Basic 2005" download that is available at By completing this tutorial you will learn the basic steps involved in creating custom snippets, and using them from within Visual Studio's Code Window...

Getting Started

This is a short and very basic tutorial about using the very powerful, yet easy-to-use FREE "Code Snippet Editor for Visual Basic 2005" download that is available at  By completing this tutorial you will learn the basic steps involved in creating custom snippets, and using them from within Visual Studio's Code Window.   Any programmer, whether newbie or seasoned pro, will find this tool extremely beneficial. 

Let's begin by opening the Snippet Editor.



This is the editor's opening screen. Move your attention to the top left of the screen and right click on the "Visual Basic" folder.





Press "Add Path..." and the "Browse For Folder" Dialog will open.



Navigate to the following path (changing [User Name] as needed):

C:\Documents and Settings\[User Name]\My Documents\Visual Studio 2005\Code Snippets\Visual Basic\My Code Snippets

This path should have been automatically created by Visual Studio during installation.  If it was not, you must manually create it through Windows Explorer. The Snippet Editor does not allow creation of a root path with the "Browse For Folder" Dialog.




Snippets Folder

You should now find a new root-folder listed under the Visual Basic Title with the name, "My Code Snippets". [Personally, I keep all my sub-folders under that one root-folder because I find it easier to search for my custom snippets that way. It is also much easier to create sub-folders than root-folders.]



Now we will create a sub-folder. Right click on the "My Code Snippets" folder and choose "Add New Folder".



You will be prompted to enter a name for the new folder. Type: VbCity Samples and press OK.



You should now find a new sub-folder Listed under "My Code Snippets" with the name, "VbCity Samples".


We are now ready to start creating a new custom snippet. Right click on the "VbCity Samples" folder and choose: Add New Snippet.



The Add New Snippet Prompt will ask you to name the new snippet, type: My YesNo Msg Snippet and press OK.



A new blank snippet has been created in the VbCity Samples folder. Double-click on the new snippet.


Create and Edit Snippets


This opens the window where you create and edit snippets. Near the top-middle of the screen, make sure the "Editor" tab is pressed. Type the following code inside the Editor window.

Dim MsgQuesText As String = "Question to prompt user goes here"

Dim MsgQuesTitle As String = "MessageBox title goes here"

Dim MsgQuesBtns As MessageBoxButtons = MessageBoxButtons.YesNo

Dim MsgQuesIcon As MessageBoxIcon = MessageBoxIcon.Question

Dim MsgQues As DialogResult = MessageBox.Show(MsgQuesText, MsgQuesTitle, MsgQuesBtns, MsgQuesIcon)

If MsgQues = Yes Then

'Yes was pressed.

'Code Goes Here


'No was pressed.

End If













[Personally, I type and test all of my code snippets in Visual Studio and later paste them in the Editor.] Now toward the lower-middle of the screen make sure the "Properties" tab is pressed.

Fill in the properties to match below.

Title: My YesNo Message

Shortcut: YesNo

Description: This is my YesNo Message Snippet Demo for




Your screen should look similar to the image above.



Now navigate to the "Imports" tab. Under Namespace type: System.Windows.Forms.DialogResult

In the Editor window, select the following text (without quotes) in your code:



Now navigate to the "Replacements" tab...



...and press the addition symbol [+]. This will create the replacement properties for the MsgQuesText String in your code. You can leave the "ID" and "Defaults to" properties as they are.

Under the "Tooltip" property, type: Type the question to ask the user.



Your screen should look like the image above. Go back in the Editor window and select: MessageBox title goes here (without quotes). Then add a replacement for that text the same way. For the Tooltip property type: Title of the YesNo MessageBox.



That's all there is to it!



Press the "Save" button located above the "Editor" tab.



Now press the "Sync" button located two buttons down from the "Save" button. Close the Snippet Editor.   It's time to use your new snippet!


Using The Snippet


Create a new project and double click on the form. Click your mouse inside the Form's load event. Right click and choose "Insert Snippet...".



Navigate through the folders to your custom snippet by double clicking. Pause when you get to your "My YesNo Message" Snippet and only click once to select it. Notice the tooltip? If you wanted to add the snippet, all you would do is double-click on the snippet's name. We don't want to add it yet so click somewhere on the page itself to close the snippet navigation.



That was the long way to add a snippet; I want to show you the shortcut now. If you accidentally added the snippet, then just delete it from the event before proceeding. Do you remember what we named the shortcut for your snippet? We named it YesNo. So type yesno inside the form's load event and press the tab key.



There's the snippet, all typed out and ready to go! [Personally, I would have typed something more meaningful for my message title so that I don't have to change it now. My real snippet's title is: Message and in most cases I just leave it that way.]  You will notice that the snippet automatically put your included import statement at the top of the code.



Double-click on the first replacement string, "Questions to prompt user goes here". The entire replacement becomes highlighted so all you need to do is start typing. Type: Would you like to continue and load the page?

Now do the same for the replacement, "MessageBox title goes here" and type: Message

Under the comment, "'Code Goes Here" in the If...Then...Else block, type: MessageBox.Show("Ok, loading form")

and under the comment, "No was pressed" type: Me.Close()

The snippet is ready to run. Press F5 and try it out.



If you press "No" the form should just close without ever opening. If you press "Yes", you should see the "Ok, loading form" message. Press OK and the form should load.



You have completed the Using the "Code Snippet Editor for Visual Basic 2005" tutorial. Thank you for participating with my first article!