100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Your First VB.NET Program

Writing, compiling, and running a minimal VB.NET console program, and understanding Sub Main, Console.WriteLine, and the build/run workflow.

FoundationsBeginner7 min readJul 10, 2026
Analogies

Your First VB.NET Program

Writing a first VB.NET program almost always means printing 'Hello, World!' to the console, a tiny exercise that nonetheless exercises the entire toolchain: the compiler (vbc.exe under the hood), the .NET runtime, and the console host, and confirms your Visual Studio installation and .NET desktop workload are correctly configured before you move on to real projects.

🏏

Cricket analogy: It's like a new fast bowler sending down a single test delivery in the nets before their first match to confirm the run-up, grip, and pitch conditions are all working, similar to a Hello World program confirming your compiler, runtime, and console host are correctly wired up.

Writing the Console Application

A minimal VB.NET console program consists of a Module containing a Sub Main procedure, since Main is the designated entry point the .NET runtime looks for when it launches your compiled executable; unlike C# which wraps Main inside a class, VB.NET conventionally uses a Module, which is implicitly shared (static) so you don't need to instantiate anything before Main runs.

🏏

Cricket analogy: It's like a team's designated opening batsman always walking out first without needing a special ceremony each match — VB.NET's Module is implicitly shared, so Sub Main just runs the moment the program starts, no instantiation needed, unlike C#'s Main sitting inside a class.

Compiling and Running

Pressing F5 in Visual Studio compiles your VB.NET source into an assembly (a .exe or .dll containing CIL) via the VB.NET compiler, then launches it under the debugger attached, letting you set breakpoints and step through Sub Main line by line; Ctrl+F5 does the same build but runs without attaching the debugger, which starts faster and is the shortcut you'll reach for once you just want to see the console output.

🏏

Cricket analogy: It's like a team having a full net session with a coach analyzing every ball in slow motion (F5 with the debugger attached) versus a quick informal throwdown session just to loosen up (Ctrl+F5 without the debugger), both bowl the same deliveries but one is slower and more instrumented.

Understanding Sub Main and Console.WriteLine

Console.WriteLine() is a shared method on the System.Console class that writes a string followed by a newline to standard output, while Console.Write() omits the trailing newline; Console.ReadLine() pauses execution and waits for the user to type input and press Enter, which is commonly added at the end of Sub Main purely so the console window stays open after the program finishes running when launched outside the debugger.

🏏

Cricket analogy: It's like a commentator announcing 'FOUR!' and then pausing for the crowd reaction before continuing (WriteLine's trailing newline) versus rattling off consecutive stats with no pause (Write with no newline), while Console.ReadLine() is like the umpire holding play until the crowd settles, keeping the 'window' open.

vbnet
Module Program
    Sub Main()
        Console.WriteLine("Hello, World!")
        Console.Write("Press Enter to exit...")
        Console.ReadLine()
    End Sub
End Module

Sub Main can optionally accept command-line arguments as Sub Main(args As String()), giving you access to any values passed after the executable name, e.g. MyApp.exe input.txt populates args(0) with 'input.txt'.

  • A minimal VB.NET console program uses a Module containing a Sub Main entry point.
  • Sub Main is the designated entry point the .NET runtime looks for at launch.
  • F5 compiles and runs with the debugger attached; Ctrl+F5 runs without it and starts faster.
  • Console.WriteLine() writes a string plus a newline; Console.Write() omits the newline.
  • Console.ReadLine() pauses execution and is often used to keep the console window open.
  • Sub Main can optionally accept command-line arguments via Sub Main(args As String()).
  • A successful Hello World run confirms your compiler, runtime, and console host are correctly configured.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#VBNETStudyNotes#YourFirstVBNETProgram#NET#Program#Writing#Console#StudyNotes#SkillVeris#ExamPrep