Close this window

Getting Started with Visual Basic.NET

Step 1. Starting Projects

Development in Visual Studio is organized around solutions, which contain one or more projects. For this tutorial, we will create a solution with a single Visual Basic project.

Creating a New Project

  1. In the Visual Studio.NET environment, select File | New | Project from the menu.

  2. Select Visual Basic on the left and then Console Application on the right.

  3. Specify the name of your project and enter the location in which to create the project. The project directory will be created automatically by Visual Studio.

  4. Click OK and you're on your way!

Your Visual Basic Solution

Visual Studio.NET has created a solution with one simple Visual Basic project. The project contains two files: assemblyinfo.vb and module1.vb.

The next few steps discuss these different files and how to compile the project.


back to top

Step 2. Hello, World!

We're sorry but we just couldn't resist the temptation... We just have to do the classic "Hello, World!" application that was first written in the C language.

Source Code Modifications

  1. Double-click the file 'module1.vb' in the Solution Explorer. You can display the Solution Explorer using the View menu.
  2. Make the changes highlighted in red to the pre-generated template (module1.vb).

    ' Import namespaces
    Imports System

    Module Module1

        Sub Main()

            Console.WriteLine ("Hello, VB.NET World!")

        End Sub

    End Module

  3. Notice that as you type, Visual Studio will help you with the names of classes and functions, since the .NET Framework publishes the type information.

Compiling Your Application

  1. Now that you have made your modifications, you can compile the Visual Basic project by simplying selecting Build in the Build menu.

  2. Errors and messages from the VB compiler will be displayed in the Output window. If there were no errors, you can run the Hello World application by clicking Start without Debugging under the Debug menu.

Program Output

This is a screenshot of the output from the Hello World sample application when run from within the Visual Studio environment.

Understanding the Changes

The WriteLine() function of the System.Console class prints the string passed to it followed by a single new line character. The function can take a number of other data types including integers and floating-point numbers.

Control passes to the Main() function after the program has been loaded. That is why we insert the call to WriteLine() in the procedure.


back to top

2001 Microsoft Corporation. All rights reserved. Terms of Use | Privacy Statement | Accessibility