Installation, Tools and First Program

2.1 Installing the Tools

Visual Studio 2022 (or newer) Community (free) → workload ".NET desktop development" (and optionally "ASP.NET and web development", "Office/SharePoint development").

The .NET SDK (installed with Visual Studio, or separately from dot.net) gives you the dotnet CLI.

Verify: dotnet --info.

VS Code has limited VB IntelliSense (no designer). Visual Studio is strongly recommended for VB.

On macOS/Linux, VB console apps and libraries build with the .NET SDK, but WinForms and WPF are Windows-only.

2.2 Creating Projects

In Visual Studio: File → New → Project → filter Language: *Visual Basic*.

dotnet new console -lang VB -n HelloVB
cd HelloVB
dotnet run
dotnet new classlib -lang VB -n MyLibrary
dotnet new winforms -lang VB -n MyWinApp      # Windows only
dotnet new wpf -lang VB -n MyWpfApp           # Windows only
dotnet new list --language VB                 # available VB templates

2.3 Hello, World

' Program.vb
Imports System

Module Program
    Sub Main(args As String())
        Console.WriteLine("Hello, World!")
        Console.Write("What is your name? ")
        Dim name As String = Console.ReadLine()
        Console.WriteLine($"Nice to meet you, {name}!")
        Console.ReadKey()   ' wait for a key press
    End Sub
End Module

2.4 Anatomy of a VB Program

Imports System Brings a namespace into scope (like using in C#) Module Program A container of shared (static) members End Sub / End Module

2.5 The Project File (.vbproj)

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <RootNamespace>HelloVB</RootNamespace>
    <OptionStrict>On</OptionStrict>
    <OptionExplicit>On</OptionExplicit>
    <OptionInfer>On</OptionInfer>
    <OptionCompare>Binary</OptionCompare>
  </PropertyGroup>
</Project>

2.6 Visual Studio Essentials

Solution Explorer, Properties window, Toolbox (GUI controls), Error List, Output, Immediate Window (evaluate code while debugging), IntelliSense, code snippets (type prop + Tab Tab), refactoring (Ctrl+.), Go To Definition (F12), Build (Ctrl+Shift+B), Run (F5), Run without debugging (Ctrl+F5).