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.CoreholdsIsbn(a validated value object),Book,Author,LoanState,Loan,CatalogItemwith itsMagazinesubtype, theICatalogStoreinterface and theCatalogthat uses it. -
Shelf.Dataoffers in-memory, JSON and SQLite with EF Core stores. -
Shelf.Cliis a console program that reads CSV withTextFieldParser, builds XML with literals, queries with LINQ and looks up ISBNs asynchronously. -
Shelf.Desktop(Windows Forms) andShelf.Wpf(WPF) are the graphical fronts, andShelf.Tests(with xUnit and NUnit variants) holds the tests. -
A small legacy corner shows the old
On Errorand 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
-
Getting Started — install the SDK or Visual Studio, build and run a first program
-
Visual Basic and .NET — what Visual Basic can and cannot build on .NET 10
-
Program Structure and Code Conventions and Option Statements — turn
Option Strict Onon from the first line -
Data Types and Literals, Type Conversions, Operators and Expressions and Control Flow
-
The My Namespace — the part of Visual Basic that other languages do not have
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:
What’s covered
Getting started
Page |
What it covers |
installing the .NET 10 SDK and Visual Studio 2026, a first console project, the generated |
|
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 |
|
BASIC to VB 17.13, a timeline, the version table with |
|
what surprises C#, Java and VB6 programmers, with side-by-side maps |
|
the IDEs and editors commonly used for Visual Basic, with links to the official pages |
Core language
Page |
What it covers |
source-file layout, |
|
|
|
every elementary type with size and range, literals, type characters, boxing and |
|
widening and narrowing, |
|
|
|
|
|
the precedence ladder, arithmetic, comparison, |
|
|
|
|
|
|
|
|
|
|
Procedures and functional features
Page |
What it covers |
|
|
|
|
the |
|
|
|
the |
Types and object-oriented programming
Page |
What it covers |
constructors, initialization order, object initializers, |
|
property procedures, auto-properties, |
|
|
|
|
|
|
|
|
|
|
|
|
|
tuple literals and names, |
|
garbage collection, |
Arrays, collections, LINQ and XML
Page |
What it covers |
upper-bound declaration, |
|
|
|
query clauses, method syntax, deferred execution and the clause pipeline |
|
XML literals, embedded expressions, namespaces and the |
Errors, async and concurrency
Page |
What it covers |
|
|
the legacy |
|
|
|
|
Runtime library, My and I/O
Page |
What it covers |
|
|
|
|
|
|
|
Compilation, binding and reflection
Page |
What it covers |
|
|
attribute syntax, caller-info attributes and reflection |
|
how members are bound, |
Interoperability
Page |
What it covers |
mixed VB and C# solutions and what Visual Basic can consume from modern C# |
|
|
|
COM references, |
Applications
Page |
What it covers |
|
|
the designer, |
|
XAML with VB code-behind, data binding and MVVM |
|
|
|
Web Forms and MVC on .NET Framework, ASP.NET Core minimal APIs written in VB, |
|
class libraries, multi-targeting, NuGet, |
Tooling
Page |
What it covers |
the |
|
the Visual Studio debugger, |
|
MSTest, xUnit.net and NUnit side by side, test doubles and coverage |
|
|
Practice, legacy and migration
Page |
What it covers |
the consolidated rules and a gotcha table |
|
parameterized SQL, secrets, hashing, password storage, encryption and safe parsing |
|
idiomatic Singleton, Factory, Observer, Strategy, Decorator and Repository |
|
how the relatives compare, their support status and the family tree |
|
VB6, VBA and .NET Framework migration paths and the legacy-to-modern table |
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).
Entry points and policies
-
Visual Basic documentation, Visual Basic language strategy and What’s new in Visual Basic
-
Visual Basic Language Specification (VB 11) and the Microsoft.VisualBasic API browser
-
.NET documentation, Windows Forms, WPF, EF Core, NuGet and Visual Studio
-
.NET support policy, .NET Framework lifecycle and .NET downloads
-
dotnet/vblang (specification, proposals and language design notes), dotnet/roslyn (the compiler), dotnet/runtime (
Microsoft.VisualBasic.Core), dotnet/winforms (Microsoft.VisualBasic.Forms) and dotnet/sdk (the project templates andMicrosoft.NET.Sdk.VisualBasicprops) -
Visual Basic support planned for .NET 5.0 and Update to the Windows Forms Visual Basic Application Framework
-
Support Statement for Visual Basic 6.0, Office VBA language reference and Windows deprecated features (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: developing applications and the My namespace
Visual Basic Guide: programming concepts (async, attributes, collections, iterators, LINQ, OOP, reflection, threading)
Visual Basic Guide: language features
Visual Basic Language Specification (VB 11)
Visual Basic compiler error pages
-
BC30064: ReadOnly variable cannot be the target of an assignment
-
BC30288: Local variable is already declared in the current block
-
BC30542: Division by zero occurred while evaluating this expression
-
BC30689: Statement cannot appear outside of a method body or declaration
-
BC36010: Using operand of type must implement System.IDisposable
Official .NET documentation (fundamentals, core, SDK, deployment, tooling)
-
Unit testing Visual Basic .NET Core libraries using dotnet test and xUnit
-
Unit testing Visual Basic .NET Core libraries using dotnet test and MSTest
-
Unit testing Visual Basic .NET Core libraries using dotnet test and NUnit
-
Choose between DateTime, DateOnly, DateTimeOffset, TimeSpan, TimeOnly and TimeZoneInfo
-
Timing vulnerabilities with CBC-mode symmetric decryption using padding
-
.NET: Customize property names and values with System.Text.Json
-
.NET: Serialize properties of derived classes with System.Text.Json