Lesson 37: Creating Console Applications in VB2019

Learn to build lightweight command-line applications with Visual Basic

Key Takeaway

Console applications are lightweight programs that run in a terminal window, perfect for utilities, scripts, and simple tools.

In this lesson, you'll learn how to create console applications in Visual Basic 2019. Unlike Windows Forms applications, console apps run in a command-line interface and are ideal for automation tasks, simple utilities, and learning core programming concepts.

Command-Line Interface

Run programs without graphical interface

Lightweight

Minimal resource requirements

Focus on Logic

Concentrate on programming fundamentals

Fast Execution

Quick startup and execution times

37.1 Creating a Console Application Project

To start creating a console application in Visual Basic 2019:

  1. Launch Visual Studio 2019
  2. Select "Create a new project"
  3. Choose "Visual Basic" as the language
  4. Select "Console App (.NET Framework)"
  5. Name your project and click "Create"
Console application project selection

Figure 37.1: Creating a new console application project

37.2 The Console Application Code Window

After creating your project, Visual Studio opens the code window with the basic structure of a console application:

Console application code window

Figure 37.2: The console application code window

The main entry point for a console application is the Sub Main() method. This is where your program starts execution.

Basic Console Application Structure
Module Module1
    
    Sub Main()
        ' Your code goes here
    End Sub

End Module

37.3 Adding Modules

You can add additional modules to your console application to organize your code:

  1. Right-click on your project in Solution Explorer
  2. Select "Add" → "Module"
  3. Name your module and click "Add"
Adding a module to a console application

Figure 37.3: Adding a new module to your project

37.4 Console Application Examples

Let's explore some practical examples of console applications.

Example 37.1: Displaying a Message

This simple program uses InputBox to get user input and MsgBox to display it:

Input and Message Display
Module Module1
    
    Sub Main()
        Dim myText As String
        myText = InputBox("Enter Your Text")
        MsgBox(myText)
    End Sub

End Module

When you run this program, you'll first see an input dialog:

InputBox example

Figure 37.4: InputBox for user input

After entering text and clicking "OK", a message box displays your input:

MsgBox example

Figure 37.5: Message box displaying user input

Example 37.2: Looping Program

This example demonstrates a looping structure using Do Until...Loop:

Looping with Do Until
Module Module1
    
    Sub Main()
        Dim x As Single
        Do Until x > 100
            x = x + 5
        Loop
        MsgBox("The value of x is " & x)
    End Sub

End Module

When executed, this program shows the final value of x after the loop completes:

Looping program output

Figure 37.6: Output of the looping program

Lesson Summary

In this lesson, you've learned the fundamentals of creating console applications in Visual Basic 2019:

Console Projects

Created new console application projects

Code Structure

Understood the role of Sub Main()

Input/Output

Used InputBox and MsgBox for interaction

Looping

Implemented Do Until loops

Console applications provide a simple way to develop and test algorithms without the complexity of a graphical interface.

Next Lesson

Continue learning console applications in Lesson 38: Console Applications Part 2.

Related Resources

VB2019 Console Guide

Comprehensive guide to console programming in VB2019

Explore Guide

Console App Samples

Practical VB2019 console application examples

View Examples

.NET Console Docs

Official Microsoft console application documentation

View Documentation

Command-Line Reference

Complete reference for command-line interfaces

Learn More