Learn to use the code editor with Visual Basic
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
In this 10-minute introduction to the code editor in Visual Studio, we'll add code to a file to look at some of the ways that Visual Studio makes writing, navigating, and understanding Visual Basic code easier.
Tip
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
This article assumes you're already familiar with Visual Basic. If you aren't, we suggest you look at a tutorial such as Create a simple Visual Basic (VB) console app first.
Tip
To follow along with this article, make sure you have the Visual Basic settings selected for Visual Studio. For information about selecting settings for the integrated development environment (IDE), see Select environment settings.
Create a new code file
Start by creating a new file and adding some code to it.
Open Visual Studio.
From the File menu on the menu bar, choose New File.
In the New File dialog box, under the General category, choose Visual Basic Class, and then choose Open.
A new file opens in the editor with the skeleton of a Visual Basic class. (You can already notice that you don't have to create a full Visual Studio project to gain some of the benefits that the code editor offers, such as syntax highlighting. All you need is a code file!)
Use code snippets
Visual Studio provides useful code snippets that you can use to quickly and easily generate commonly used code blocks. Code snippets are available for different programming languages including Visual Basic, C#, and C++. Let's add the Visual Basic Sub snippet to our file.
Comment out code
The toolbar, which is the row of buttons under the menu bar in Visual Studio, can help make you more productive as you code. For example, you can toggle IntelliSense completion mode, increase or decrease a line indent, or comment out code that you don't want to compile. (IntelliSense is a coding aid that displays a list of matching methods, amongst other things.) In this section, we'll comment out some code.