Visual Basic Reference

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

The reference material consulted while preparing these pages is listed in the section bibliography.

This section is written against Visual Basic 17.13 on .NET 10 (LTS) with the .NET SDK 10.0.402 and Visual Studio 2026, checked on 2026-10-19. .NET 10 is supported until 2028-11-14. .NET 11 was still a release candidate on the check date (SDK 11.0.100-rc.2, general availability expected in November 2026), so it is treated as upcoming, and its compiler accepts the same LangVersion values as the .NET 10 one. Every example was built, and run where it can run, with the official mcr.microsoft.com/dotnet/sdk container image, with Option Strict On and warnings treated as errors, and the output shown is the real output. Windows-only examples (Windows Forms, WPF, COM, Declare against Windows libraries, My.Computer devices) were built but not run.

What Visual Basic is

Visual Basic is a statically typed (optionally late-bound), case-insensitive, object-oriented language for .NET with English-like syntax. It descends from BASIC and from Visual Basic 6, which Microsoft replaced in 2002 with a language that shares the name and much of the spirit but runs on the common language runtime: the Roslyn compiler turns .vb files into IL, and the same libraries, tools and runtime serve C# and F#. Visual Basic is stable and maintained by Microsoft, and it is strongest for Windows desktop applications, class libraries, automation and the large body of existing code that has to be kept running.

Microsoft’s language strategy is the one thing to know before choosing it for new work: Visual Basic is kept stable, it receives the features that .NET and its runtime require it to consume (a "consumption-only" approach), it is not extended to new workloads, and the Visual Studio tooling for it keeps being maintained. In practice that means Windows Forms, WPF, console programs, libraries and tests in Visual Basic are fully supported on .NET 10, while ASP.NET Core web applications, Blazor, .NET MAUI and WinUI 3 are built in C#, with Visual Basic libraries behind them where that helps. The dated sources are on History, Versions and Language Strategy and Visual Basic and .NET.

The shelf scenario

The examples across the section share one small, original domain: shelf, a library catalogue written as a .NET solution (Shelf.slnx). It is deliberately the same domain as the Rust Reference, the Go Reference and the Ruby Reference, so you can compare the languages on the same types.

  • Shelf.Core holds Isbn (a validated value object), Book, Author, LoanState, Loan, CatalogItem with its Magazine subtype, the ICatalogStore interface and the Catalog that uses it.

  • Shelf.Data offers in-memory, JSON and SQLite with EF Core stores.

  • Shelf.Cli is a console program that reads CSV with TextFieldParser, builds XML with literals, queries with LINQ and looks up ISBNs asynchronously.

  • Shelf.Desktop (Windows Forms) and Shelf.Wpf (WPF) are the graphical fronts, and Shelf.Tests (with xUnit and NUnit variants) holds the tests.

  • A small legacy corner shows the old On Error and late-bound style next to its modern replacement.

The pages build on each other, and the cheat sheet summarises them. Each page shows the pieces of the solution it needs.

New here? Read in this order

  1. Getting Started — install the SDK or Visual Studio, build and run a first program

  2. Visual Basic and .NET — what Visual Basic can and cannot build on .NET 10

  3. Program Structure and Code Conventions and Option Statements — turn Option Strict On on from the first line

  4. Data Types and Literals, Type Conversions, Operators and Expressions and Control Flow

  5. Procedures: Sub and Function and Classes and Objects

  6. Arrays, Collections and LINQ Query Expressions

  7. Structured Exception Handling

  8. The My Namespace — the part of Visual Basic that other languages do not have

  9. Projects, MSBuild and the dotnet CLI and Testing

  10. Best Practices and Common Pitfalls

Then pick topics as you need them, and keep the cheat sheet at hand. If you come from C# or Java, start with Visual Basic for Programmers of Other Languages.

Coming from VB6, VBA or VBScript?

Visual Basic 6, Office VBA and VBScript are relatives, not versions, of the language in this section: they have their own runtimes, type systems, error handling and object models, and their own support stories (the VB6 runtime is supported only as part of Windows, and VBScript is deprecated). Start with The VB Family: VB6, VBA and VBScript to see how they differ, then read Migrating Legacy Visual Basic for the migration paths and the legacy-to-modern table. The legacy constructs that still compile are explained on Unstructured Error Handling (On Error) and Early and Late Binding, and old books and tutorials are corrected in prose on the page that covers each concept.

The whole section at a glance:

mindmap root((Visual Basic Reference)) Getting started Toolchain .NET platform History and strategy Core language Option statements Types and conversions Operators Control flow Strings and dates Procedures Sub and Function Lambdas and delegates Iterators Generics Object-oriented Classes and properties Inheritance Interfaces Events Structures Data Arrays Collections LINQ XML literals Errors and concurrency Try Catch On Error Async Await Threads Runtime and I/O My namespace Runtime library Files Serialization Interop and applications C# and COM Declare and P/Invoke Console Windows Forms and WPF Data access Web and libraries Tooling and practice MSBuild and CLI Debugging Testing Analyzers Security Patterns Legacy VB6 VBA VBScript Migration

What’s covered

Getting started

Page

What it covers

Getting Started

installing the .NET 10 SDK and Visual Studio 2026, a first console project, the generated .vbproj, how a build turns .vb files into a running program and how to read compiler errors

Visual Basic and .NET

the CLR, IL and the Common Type System in VB terms, .NET versus .NET Framework, and the support matrix of what Visual Basic can build on .NET 10

History, Versions and Language Strategy

BASIC to VB 17.13, a timeline, the version table with LangVersion values and Microsoft’s consumption-only language strategy

Visual Basic for Programmers of Other Languages

what surprises C#, Java and VB6 programmers, with side-by-side maps

IDEs & Tools

the IDEs and editors commonly used for Visual Basic, with links to the official pages

Core language

Page

What it covers

Program Structure and Code Conventions

source-file layout, Imports, namespaces, comments, line continuation and naming conventions

Option Statements

Option Explicit, Strict, Infer and Compare, their defaults and what Option Strict On forbids

Data Types and Literals

every elementary type with size and range, literals, type characters, boxing and Object

Type Conversions

widening and narrowing, CType, DirectCast, TryCast, the C... functions and banker’s rounding

Variables, Constants and Scope

Dim, Static, Const, ReadOnly, access modifiers, scope and the uninitialized loop-local pitfall

Enumerations

Enum, underlying types, Flags and the System.Enum helpers

Operators and Expressions

the precedence ladder, arithmetic, comparison, Like, &, short-circuiting and If()

Control Flow

If, Select Case, the loop statements, With, Exit and Continue, GoTo

Nothing and Nullable Value Types

Nothing as a default value, Is Nothing, Nullable(Of T) and three-valued logic

Strings and Text

String and Char, interpolation, ControlChars, one-based runtime functions and StringBuilder

Dates, Times and Formatting

Date, DateTime, DateOnly, TimeSpan, time zones and format strings

Numbers and Math

Math, rounding modes, Decimal, floating-point special values and BigInteger

Procedures and functional features

Page

What it covers

Procedures: Sub and Function

Sub and Function, ByVal and ByRef, Optional, ParamArray, named arguments and overload resolution

Delegates and Lambda Expressions

Delegate, AddressOf, relaxed conversion, Func and Action, lambdas and closures

Extension Methods and Partial Methods

the Extension attribute, resolution rules and partial types and methods

Iterators and Yield

Iterator functions, Yield, deferred execution and the generated state machine

Generics

the Of clause, constraints, variance, generic procedures and the ICatalogStore / Repository class diagram

Types and object-oriented programming

Page

What it covers

Classes and Objects

constructors, initialization order, object initializers, Me, Shared members and access

Properties and Default Properties

property procedures, auto-properties, ReadOnly, parameterized and Default properties

Modules and Shared Members

Module, Shared members, type promotion and Sub Main

Structures and Value Types

Structure, value semantics, boxing and mutable-struct pitfalls

Inheritance and Polymorphism

Inherits, Overridable, Overrides, Shadows, MustInherit, MyBase and constructor chaining

Interfaces

Interface, the Implements clause, renaming, explicit implementation and default interface members

Events and Handlers

Event, RaiseEvent, WithEvents and Handles, AddHandler and custom events

Operator Overloading and Equality

Operator procedures, CType conversions, Equals, GetHashCode and IComparable

Tuples and Anonymous Types

tuple literals and names, ValueTuple, anonymous types and Key properties

Object Lifetime and Disposal

garbage collection, Using, IDisposable, finalizers and weak references

Arrays, collections, LINQ and XML

Page

What it covers

Arrays

upper-bound declaration, ReDim Preserve, Erase, jagged and rectangular arrays, Array helpers

Collections

List(Of T), Dictionary, sets, queues, stacks, initializers and immutable and concurrent collections

LINQ Query Expressions

query clauses, method syntax, deferred execution and the clause pipeline

XML Literals and Axis Properties

XML literals, embedded expressions, namespaces and the .<child>, .@attr and ...<descendant> axes

Errors, async and concurrency

Page

What it covers

Structured Exception Handling

Try, Catch ... When, Finally, Throw, custom exceptions and exception filters

Unstructured Error Handling (On Error)

the legacy On Error model, Resume, Err and why not to mix it with Try

Async and Await

Async Function, Await, Task, cancellation, the missing async Main and the HttpClient sequence

Threads, Parallelism and Synchronization

Thread, the thread pool, SyncLock, Interlocked, Parallel and concurrent collections

Runtime library, My and I/O

Page

What it covers

The My Namespace

My and MyType, My.Application, My.Computer, My.Settings, My.Resources and My.User

The Visual Basic Runtime Library

Microsoft.VisualBasic modules, Collection, Err, Constants and ControlChars

Files, Directories and Streams

System.IO, encodings, My.Computer.FileSystem and TextFieldParser

Serialization: JSON and XML

System.Text.Json, XmlSerializer, DataContractSerializer and the BinaryFormatter removal

Compilation, binding and reflection

Page

What it covers

Conditional Compilation and Directives

#If, #Const, #Region, #Disable Warning and predefined constants

Attributes, Caller Information and Reflection

attribute syntax, caller-info attributes and reflection

Early and Late Binding

how members are bound, Option Strict Off, CallByName and Object late binding

Interoperability

Page

What it covers

Interop with C# and Other .NET Languages

mixed VB and C# solutions and what Visual Basic can consume from modern C#

Native Interop: Declare and P/Invoke

Declare, DllImport, marshalling and callbacks

COM Interop and Office Automation

COM references, CreateObject, early and late bound Office automation and exposing VB classes to COM

Applications

Page

What it covers

Console Applications

Sub Main, arguments, exit codes, input and output and the Generic Host

Windows Forms Applications

the designer, Handles, the Application Framework start-up sequence and layout

WPF Applications

XAML with VB code-behind, data binding and MVVM

Data Access: ADO.NET and EF Core

Microsoft.Data.SqlClient, SQLite, Dapper and EF Core, with a "which data-access API?" flowchart

Web, HTTP and Services

Web Forms and MVC on .NET Framework, ASP.NET Core minimal APIs written in VB, HttpClient

Libraries, Packaging and Deployment

class libraries, multi-targeting, NuGet, dotnet publish, trimming and Native AOT

Tooling

Page

What it covers

Projects, MSBuild and the dotnet CLI

the .vbproj, every VB MSBuild property and vbc option, and the dotnet commands

Debugging and Diagnostics

the Visual Studio debugger, Debug and Trace, logging and dumps

Testing

MSTest, xUnit.net and NUnit side by side, test doubles and coverage

XML Documentation, Analyzers and Code Style

''' comments, .NET analyzers, .editorconfig and DocFX

Practice, legacy and migration

Page

What it covers

Best Practices and Common Pitfalls

the consolidated rules and a gotcha table

Security and Cryptography

parameterized SQL, secrets, hashing, password storage, encryption and safe parsing

Design Patterns in Visual Basic

idiomatic Singleton, Factory, Observer, Strategy, Decorator and Repository

The VB Family: VB6, VBA and VBScript

how the relatives compare, their support status and the family tree

Migrating Legacy Visual Basic

VB6, VBA and .NET Framework migration paths and the legacy-to-modern table

Cheat sheet

Page What it covers

Cheat Sheet (PDF)

a one-page A4 summary of the whole section, with a strip of legacy constructs and their modern replacements

Bibliography

Books

  • Aspen Olmsted, Visual Basic Quickstart Guide: Improve your programming skills and design applications that range from basic utilities to complex software, 1st edition. Packt Publishing, 2023. ISBN 978-1-80512-531-0. Publisher page (the publisher blocks scripted access, so the page was not machine-verified); companion code. It uses the .NET Framework templates of Visual Studio 2019 and 2022.

  • Kameron Hussain and Frahaan Hussain, Mastering VB.NET: A Comprehensive Guide to Visual Basic .NET Programming, 1st edition. Sonar Publishing, 2023. ISBN 979-8-215-62411-1. The publisher has no website of its own, so the link is the Bookshop.org retailer listing, a retailer and not a publisher page (the site blocks scripted access, so the listing was not machine-verified).

The books are consulted references, not the primary source: no text, listing, figure or exercise was taken from them, and every example was written against the current official documentation. On any discrepancy, and wherever a book is silent on a later feature, the official documentation wins; where a book shows an outdated form, the pages say so in prose (collected on History, Versions and Language Strategy and The VB Family: VB6, VBA and VBScript).

Specifications

Cited by the pages that use them: ECMA-335, Common Language Infrastructure, IEEE 754, floating-point arithmetic (Single and Double; the site blocks scripted access), RFC 4180, CSV (TextFieldParser), RFC 8259, JSON, Extensible Markup Language (XML) 1.0 and Namespaces in XML.

Every source cited on the pages

The lists below hold the sources that the pages of this section cite in their == References headings and Source: lines, grouped by area and sorted by address. Each link goes to the official site or repository. Individual pages list the subset they derive from.

Visual Basic Guide: language features

Visual Basic Language Reference

API browser: System, Microsoft.Data and other namespaces

Official .NET documentation (fundamentals, core, SDK, deployment, tooling)