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.
Module Program
Sub Main()
Console.WriteLine("Hello, World!")
Console.Write("Press Enter to exit...")
Console.ReadLine()
End Sub
End ModuleSub 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
1. Which VB.NET construct typically holds the Sub Main entry point in a console app?
2. What is the difference between Console.WriteLine() and Console.Write()?
3. What does pressing Ctrl+F5 do differently from F5 in Visual Studio?
4. Why is Console.ReadLine() commonly added at the end of Sub Main?
5. How do you access command-line arguments passed to a VB.NET console app?
Was this page helpful?
You May Also Like
Installing Visual Studio and Setup
A practical walkthrough of installing Visual Studio, selecting the correct workload, and creating your first VB.NET project.
VB.NET Syntax and Variables
Core VB.NET syntax rules — statements, case-insensitivity, variable declarations with Dim, naming conventions, scope, and comments.
What Is VB.NET?
An introduction to VB.NET, a modern, object-oriented .NET language derived from classic Visual Basic, covering its history, ecosystem role, and comparison to C#.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics