Lesson 37

Console Application Part 1

In this lesson, you will learn how to create console applications in Visual Basic 2015 and understand how code is structured using modules and Sub Main.

37.1 Introduction to Console Applications

Besides Windows Forms applications, Visual Basic 2015 also allows you to build console applications.

Console applications run in a text-based environment and are commonly used for:

  • Learning programming fundamentals
  • Testing logic and algorithms
  • Building lightweight tools

To create a console application:

  • Open Visual Basic 2015
  • Select Console Application
  • Click Create Project

Figure 37.1 – Creating a Console Application

37.2 Understanding the Code Structure

When a console application is created, the code is placed inside a Module. The main entry point of the program is:

Sub Main()

    ' Your code here

End Sub

All code execution begins inside Sub Main().

You can also add additional modules by:

  • Click Project → Add Module

Figure 37.2 – Adding Modules

37.3 Example 1: Displaying a Message

The following example displays a message using the MsgBox() function:

Sub Main()

    MsgBox("Welcome to Visual Basic 2015 Console Programming")

End Sub

When you run the program, a message box will appear displaying the message.

Figure 37.3 – Output Message

37.4 Example 2: A Looping Program

You can create loops using the Do Until...Loop structure.

Sub Main()

    Dim x As Single

    Do Until x > 10
        x = x + 1
    Loop

    MsgBox("The value of x is " & x)

End Sub

Output:

The value of x is 11

Build on This Foundation

Continue to VB2026

After learning the basics of checkbox controls in VB2015, move to the newest VB2026 tutorial for a more modern VB.NET learning path.

Explore VB2026 →

Visual Basic Programming

Visual Basic Programming

Use this Top Release book to reinforce your tutorial learning with a more structured guide.

Key Takeaways:
  • Console apps run in a text-based environment
  • Program starts from Sub Main()
  • Modules organize code
  • Loops and logic work the same as Windows Forms

Next: Console App Part 2

Go to Lesson 38 →