Visual Basic .NET Tutorial
Learn Visual Basic .NET step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Visual Basic .NET? Learn what Visual Basic .NET is, how it differs from classic VB6 and VBA, what it runs on, where it is still used and what the status of the language is today.
- Setting Up and Your First Program Install the tools for Visual Basic .NET, create a console project with Visual Studio or the dotnet CLI, write Hello World and learn how Sub Main, Console and comments work.
- Project Structure and Compilation Understand a Visual Basic .NET solution: the .vbproj file, root namespace, Imports, assemblies, Option statements, build configurations and what the compiler really does.
- VB.NET and C# Side by Side Compare Visual Basic .NET and C# syntax for variables, conditions, loops, methods, classes and operators, so you can read both languages and use the runnable C# examples on this site.
Syntax and Types
- Variables and Data Types Learn how to declare variables in Visual Basic .NET with Dim, Const and type inference, and how Integer, Long, Double, Decimal, Boolean, Char and String behave, including value versus reference types.
- Operators and Expressions Learn every operator in Visual Basic .NET: arithmetic, assignment, comparison, logical and bitwise operators, the string operators & and Like, precedence, short-circuiting and If() expressions.
- Strings and Text Work with text in Visual Basic .NET: immutable strings, concatenation, interpolation, formatting, searching, splitting, comparing, StringBuilder, Char methods and culture-safe conversions.
- Option Strict and Type Conversions Understand widening and narrowing conversions in Visual Basic .NET, why Option Strict On matters, and how to convert safely with CInt, CType, DirectCast, Convert and TryParse.
- Nullable Values and Dates Learn nullable value types (Integer?), HasValue and GetValueOrDefault, then work with Date, DateTime, TimeSpan, date arithmetic, formatting, parsing and time zones in Visual Basic .NET.
Control Flow and Procedures
- If Statements and Select Case Make decisions in Visual Basic .NET with If/ElseIf/Else, single-line If, the If() operator and Select Case with ranges, lists and comparisons, plus guard clauses and common mistakes.
- Loops in VB.NET Repeat work in Visual Basic .NET with For...Next, For Each, While, Do...Loop (While and Until), Exit and Continue statements, nested loops, Step values and the most common loop mistakes.
- Subs and Functions Write reusable procedures in Visual Basic .NET: Sub versus Function, Return, ByVal and ByRef, Optional and named arguments, overloading, recursion, lambdas and scope, with examples and common mistakes.
- Arrays in VB.NET Learn Visual Basic .NET arrays: declaring and initializing, the upper-bound rule, ReDim Preserve, multidimensional and jagged arrays, sorting, searching, copying and the most common array mistakes.
- Error Handling with Try...Catch Handle errors in Visual Basic .NET with Try...Catch...Finally, exception filters (When), Throw, custom exception classes and Using; learn what not to catch and how to avoid exceptions with validation.
Classes and Objects
- Classes, Objects and Properties Learn object-oriented programming in Visual Basic .NET: declaring classes, fields, properties with validation, constructors (Sub New), Me, Shared members, access modifiers, With blocks and object initializers.
- Inheritance, Polymorphism and Interfaces Learn inheritance in Visual Basic .NET: Inherits, MyBase, Overridable and Overrides, MustInherit and MustOverride, NotInheritable, polymorphism, Implements, and how to choose between abstract classes and interfaces.
- Events and Delegates Learn events in Visual Basic .NET: delegates, Event and RaiseEvent, WithEvents with Handles, AddHandler and RemoveHandler, EventArgs, and Action/Func delegates, including the observer pattern and common pitfalls.
- Modules, Structures, Enums and Generics Finish the object model in Visual Basic .NET: Module versus Class, Structure value types, Enum with Flags, generic classes and methods with (Of T) and constraints, extension methods and partial classes.
Collections and LINQ
- Arrays and Lists Learn VB.NET arrays and List(Of T) - declaring, upper bounds, ReDim Preserve, multidimensional and jagged arrays, adding, removing, sorting and searching, with C# stand-ins you can run.
- Dictionaries, Sets and Queues Learn VB.NET Dictionary(Of K, V), HashSet(Of T), Queue(Of T), Stack(Of T) and SortedDictionary - lookups, TryGetValue, set operations, FIFO and LIFO - with runnable C# stand-ins.
- LINQ Basics Learn LINQ in VB.NET - From, Where, Select, Order By query syntax, extension methods and lambdas, First, Any, Count, Sum, Average, plus runnable C# stand-ins that use the same operators.
- LINQ Grouping, Joins and Lazy Evaluation Master advanced LINQ in VB.NET - Group By, Join, Group Join, Distinct, Aggregate, ToLookup, SelectMany and deferred execution pitfalls, with runnable C# stand-ins using the same operators.
Windows Forms
- Windows Forms Overview Understand VB.NET Windows Forms - the Form class, designer files, partial classes, Application.Run and the message loop, project setup on modern .NET, with read-only VB and runnable C# stand-ins.
- Controls and Events Learn VB.NET WinForms controls and events - Button, TextBox, ListBox, CheckBox, Handles, WithEvents, AddHandler, sender and EventArgs - with read-only VB and runnable C# event stand-ins.
- Layout, Dialogs and Menus Learn WinForms layout in VB.NET - Anchor, Dock, TableLayoutPanel, FlowLayoutPanel, MessageBox, OpenFileDialog, custom dialogs with DialogResult, MenuStrip and StatusStrip - with runnable C# stand-ins.
- Data Binding and Validation Learn WinForms data binding and validation in VB.NET - BindingSource, DataBindings, INotifyPropertyChanged, BindingList, Validating events and ErrorProvider - with runnable C# stand-ins.
Files and Databases
- Text Files and Streams Learn VB.NET file handling - File.ReadAllText, StreamReader and StreamWriter, Path and Directory, Using blocks, encodings, CSV parsing, My.Computer.FileSystem and error handling, with runnable C# stand-ins.
- JSON and XML Serialization Learn VB.NET JSON and XML handling - System.Text.Json serialize and deserialize, JsonSerializerOptions, XML literals, XElement and LINQ to XML, XmlSerializer - with read-only VB and runnable C# stand-ins.
- ADO.NET and DataTables Learn ADO.NET in VB.NET - connections, commands, parameters, DataReader, DataAdapter, DataTable, DataView, DataSet and relations. Real provider code is read-only, DataTable stand-ins run live.
- Database Access Patterns Structure database code in VB.NET - the repository pattern, interfaces, unit of work, transactions, Dapper and Entity Framework Core basics (read-only) with a runnable in-memory repository stand-in in C#.
Interop and Migration
- VB.NET and C# Side by Side Compare VB.NET and C# syntax side by side - declarations, operators, loops, classes, properties, events, lambdas, LINQ, gotchas such as 1-based bounds and And versus AndAlso, with runnable C# equivalents.
- Interop: P/Invoke, COM and Mixed Solutions Learn VB.NET interop - calling C# libraries from VB, P/Invoke with DllImport, marshaling strings and structs, COM and Office automation, late binding, plus runnable C# stand-ins.
- Migrating to Modern .NET Plan a VB.NET migration from .NET Framework 4.x to modern .NET - SDK-style projects, the upgrade assistant, compatibility analysis, My namespace, WinForms support, strangler pattern, tests and what VB cannot do.
Projects and Practice
- Project: Expense Tracker Build a VB.NET expense tracker step by step - model, service layer, LINQ summaries, CSV persistence, a WinForms front end (read-only) and a fully runnable C# stand-in of the core logic.
- Project: Grade Book Build a console grade book in VB.NET - classes, interfaces, dictionaries, LINQ statistics, letter grades, menus and input validation, with the VB program read-only and a runnable C# stand-in.
- Practice Exercises and Solutions Practice VB.NET with ten graded exercises on collections, LINQ, events, binding, files and data access. Try each yourself in VB, then compare with runnable C# reference solutions.