Lumenary CS · Programming languages
Visual Basic
The readable, English-like language that brought programming to millions of Windows developers: Visual Basic .NET today, and how to maintain and migrate the code it left behind.
Visual Basic is one of the most influential languages in the history of personal computing. Classic Visual Basic, released by Microsoft in 1991, let people build Windows applications by drawing forms and writing short pieces of BASIC code behind buttons, and through the 1990s it was one of the most popular ways to build Windows software. In 2002 it was redesigned as Visual Basic .NET, a fully object-oriented language on .NET that compiles to the same code as C#. Its sibling, VBA (Visual Basic for Applications), still automates Microsoft Office. Microsoft supports Visual Basic on modern .NET, mainly for Windows desktop applications, class libraries and console programs, but has said that it will not evolve the language further: its design is stable, and new .NET features are made usable from it without new syntax.
This course is for anyone who has finished the Start level of Lumenary CS or has equivalent experience, and especially for those who will maintain, modernise or migrate Visual Basic code: a very large amount of it still runs businesses, laboratories and public services. In eight lessons it covers the history and present status of the language, modules and Sub Main, variables and types, control flow, procedures and functions, classes, collections and LINQ, files, text formatting and asynchronous code, error handling, and how professionals maintain and migrate Visual Basic code, including the move from Visual Basic 6 and to C#, ending with a complete program and where to go next.
To run the examples, install the .NET 10 SDK from the official download page, create a project with dotnet new console -lang VB, replace its Program.vb with an example, and run dotnet run. There is no official online playground; the community site .NET Fiddle can run Visual Basic .NET in the browser. Every complete Visual Basic program in these lessons was compiled and run as a console project with the .NET 10 SDK (whose Visual Basic compiler defaults to language version 17.13), and the one C# program, used for comparison in the migration lesson, was run with the same SDK; the output shown is the output each printed.
- Chloe · The Designer
“Why is the language built this way?” - Margaret · The Profiler
“What does it print, and what does it cost?” - Gideon · The Language Lawyer
“What exactly does the language guarantee?”
Foundations · 2 lessons
The language
Where Visual Basic came from and where it stands today, how a program is laid out in modules with Sub Main, and the types, operators and control flow of everyday code.
- 1First steps with Visual BasicFrom BASIC to Visual Basic 6 to Visual Basic .NET, where the language stands today, and your first programs. 50 min
- 2Variables, types and control flowVisual Basic's types and operators, the conversions Option Strict makes you write, and its readable decision and loop statements. 55 min
Practice · 4 lessons
Building programs
Organise code into procedures and functions, model data with classes, properties, interfaces and events, process data with collections and LINQ, and work with files, text and asynchronous input and output.
- 3Procedures and functionsSubs and Functions, how arguments are passed, optional and named parameters, Static locals, tuples, lambdas and delegates. 55 min
- 4Classes, interfaces and eventsDefining your own types with properties and constructors, inheritance and interfaces, structures, and the events that drive Windows applications. 60 min
- 5Collections, LINQ and XMLLists, dictionaries and sets, Visual Basic's rich query syntax, and XML literals, a feature very few languages have ever offered. 60 min
- 6Files, text and asynchronous codePaths, files and folders with System.IO, CSV and culture-aware formatting, and Async and Await for input and output that does not block. 60 min
Professional · 2 lessons
Living with Visual Basic code
Handle errors in modern and legacy styles, maintain, upgrade and migrate Visual Basic codebases the way professionals do, and build a complete, tested program.
- 7Errors, legacy code and migrationStructured exceptions with Try, Catch, When and Using, the On Error style you will meet in old code, and how professionals upgrade and migrate Visual Basic systems safely. 65 min
- 8A complete program, and where to go nextA payment statement for a coffee cooperative, written as idiomatic modern Visual Basic, tested with xUnit, and the paths that lead on from here. 60 min
Further reading and resources
- Visual Basic documentation · MicrosoftThe official guide and language reference.
- Visual Basic language specification · MicrosoftThe specification of Visual Basic 11, maintained in the dotnet/vblang repository.
- Visual Basic language strategy · MicrosoftMicrosoft's statement of how Visual Basic will (and will not) change.
- dotnet/vblangThe repository for the Visual Basic language design and specification.
- Download .NET · MicrosoftThe official SDK installers; Visual Basic is included.
- .NET FiddleA community site that runs C#, F# and Visual Basic .NET in the browser.