Introduction
Visual Basic is a family of programming languages from Microsoft with a readable, keyword-heavy syntax: blocks end with End If, Next or Loop instead of braces, names are not case-sensitive, and a statement ends at the end of the line. The best-known member today is Visual Basic .NET (files ending .vb), which is compiled by the Roslyn compiler for the .NET platform. Its older relatives share the look but are different languages with their own files: Visual Basic 6 (.bas modules, .cls classes, .frm forms, .vbp projects), VBA (Visual Basic for Applications, the macro language inside Office, which exports the same .bas, .cls and .frm files) and VBScript (.vbs, a scripting language for Windows Script Host and classic ASP).
All of them are text files. Visual Basic .NET source is read as UTF-8 (older files are often Windows-1252), with CR LF or LF line ends; the language lets a line continue with an underscore or, in most places, with no mark at all. These pages describe the files and the languages in them. The .NET language is described first (file structure, lexical structure, types, operators, statements, procedures, classes, generics, queries, XML literals, the library and preprocessing directives); the pages for VB6, VBA, VBScript and the VB6 form and project files follow, then the version history and the tools.
Option Strict On
Imports System.Collections.Generic
''' <summary>A shape with a name and an area.</summary>
Public MustInherit Class Shape
Public ReadOnly Property Name As String
Protected Sub New(name As String)
Me.Name = name
End Sub
Public MustOverride Function Area() As Double
End Class
Public Class Circle
Inherits Shape
Private ReadOnly _radius As Double
Public Sub New(radius As Double)
MyBase.New("circle")
_radius = radius
End Sub
Public Overrides Function Area() As Double
Return Math.PI * _radius ^ 2
End Function
End Class
Module Program
Sub Main(args As String())
Dim shapes As New List(Of Shape) From {New Circle(1.0), New Circle(2.5)}
Dim big = From s In shapes Where s.Area() > 5 Select s.Name
Console.WriteLine($"{big.Count()} large shape(s), total area {shapes.Sum(Function(s) s.Area()):N2}")
End Sub
End Module
The kinds of file
| Extension | What it is | Page |
|---|---|---|
.vb | Visual Basic .NET source: namespaces, modules, classes, structures, interfaces and enumerations; compiled with the others of a project (the same extension also names Nintendo Virtual Boy ROMs, see below) | File structure |
.vbs | VBScript: a script run by Windows Script Host (cscript, wscript), by an HTML Application, or inside classic ASP pages | VBScript |
.bas | a Visual Basic 6 or VBA standard module (procedures and variables without a class); the same extension is also used for QuickBASIC and other BASIC programs | VB6 and VBA |
.cls | a VB6 or VBA class module; the extension is also used by LaTeX class files, Salesforce Apex classes and Caché ObjectScript classes | VB6 and VBA |
.frm | a VB6 or VBA form: a header that describes the form and its controls, then the code (the binary .frx beside it holds pictures and long strings) | VB6 forms and projects |
.ctl, .pag, .dob, .dsr | a VB6 user control, property page, user document and designer: the same header and code shape as a form | VB6 forms and projects |
.vbp, .vbg | a VB6 project file (key=value lines that list the files and the references) and a project group | VB6 forms and projects |
.vbproj | the MSBuild project of a Visual Basic .NET project: XML, not Visual Basic (not described here) | Tooling |
How the viewer reads each file
A file is shown as coloured text under its own name. One scanner reads the .NET language (every literal form, the contextual keywords, XML literals, interpolated strings, directives) and a lighter mode of it reads each of the older languages: VBScript, VB6 and VBA code with the form header and Attribute lines, and project files. A .vb file has an unusual neighbour: the Nintendo Virtual Boy used .vb as one of its ROM extensions (.vboy is the other).
| File | Shown as | Page |
|---|---|---|
.vb with text in it | Visual Basic source file. A Virtual Boy ROM is binary (a power-of-two size from 16 KiB to 16 MiB, a title in printable characters 0x220 bytes before the end, a reset vector that is a jump into the ROM), so a file that opens as text is never a ROM, and a file that is a ROM is not text: the first test that fits takes the file | File structure |
.vb that is a Virtual Boy ROM | Nintendo Virtual Boy ROM, shown by the Virtual Boy viewer | .VB Virtual Boy |
.vb that is neither | the neutral name “Visual Basic source or Virtual Boy ROM”, with no reading | .VB Virtual Boy |
.vbs | VBScript file | VBScript |
.bas | Visual Basic 6 or VBA standard module when the text has an Attribute VB_ line or reads as VB6 or VBA code; otherwise a BASIC source file, shown without colour | VB6 and VBA |
.cls | Visual Basic 6 or VBA class module; a LaTeX class file, an Apex class, a Caché ObjectScript class or other text when the text says so (those are shown without colour) | VB6 and VBA |
.frm, .ctl, .pag, .dob, .dsr | Visual Basic 6 form, user control, property page, user document or designer when the text has the VERSION header; other text is shown without colour | VB6 forms and projects |
.vbp, .vbg | Visual Basic 6 project file or project group | VB6 forms and projects |
Not described
Known, not yet covered
- Reference: the sources read were the Visual Basic Language Specification (the Markdown text in dotnet/vblang, which describes version 11 of the language), the Roslyn scanner and keyword table, the language version history of dotnet/vblang and the Visual Basic for Applications documentation (MicrosoftDocs/VBA-Docs). The Visual Basic 6 documentation, most of the VBScript documentation (only the table of functions of the archived reference was read) and the Microsoft Open Specifications document [MS-VBAL] (the VBA language specification) could not be fetched in this pass (the published address of the PDF and the learn.microsoft.com address of the specification returned errors, an archive.org copy is blocked for this tool, and no public repository of the VB6 and VBScript documents was found); the VB6, VBA and VBScript pages are written from the VBA documentation, from real files and from knowledge of the languages, and say so where it matters.
- Reference: features added after the specification text (tuples, digit separators, binary literals, interpolated strings, multi-line strings, comments after line continuation,
Private Protected,NameOf,?.,Awaitin more places, the nullable andunmanageditems of later versions) come from the Roslyn scanner, the version history and the language documentation; their grammar is described in prose, not in the specification’s grammar notation. - Reference: the parser of Roslyn (which words are contextual where, error recovery) was not read; the contextual keywords are described from the scanner’s keyword table and the specification.
- Viewer: the colouring follows the text and not the program. Names are told apart by their place (after
As,Of,Imports,Suband the like); a library function of the runtime is coloured only when it is followed by a bracket in .NET code; a conditional-compilation branch that is switched off is still read as code; contextual keywords are decided from the words near them and not from a parse. - Viewer: full-width (East Asian) forms of keywords, digits, quotes and operators, which Roslyn accepts, are not read as such;
.vbhtml(Razor),.vbe(encoded VBScript),.wsf(Windows Script file, XML),.vba(an OLE container),.frx,.ctxand.vbware not read.
Unknown
- Reference: the Visual Basic .NET examples on these pages were compiled with the .NET 10 SDK (Roslyn 5.9) found on this Mac, under
Option Strict On, and the preprocessor constants and compiler options were read from that compiler; the VB6, VBA and VBScript examples were not run (no host for them was available) and were checked only by reading and with the viewer’s scanner. - Viewer: tested on hand-written cases for every token form, on one-megabyte worst cases, and on Visual Basic found for the purpose: the .NET sources on this Mac (the libwmp3, TAPI and e-mail samples) and downloaded projects (CompactGUI, PolicyPlus, Display Driver Uninstaller, WakeOnLAN, RemoteApp Tool and the dotnet/vblang samples), VBA and VB6 code from VBA-JSON, VBA-Dictionary, VBA-Web and stdVBA, and the VB6 forms, classes, modules and projects on this Mac. Code of other styles (ASP pages, Office macros with Windows-only forms, very old VB1 to VB3 files) was not available to test.
Links
Software
- Visual Studio – Microsoft’s IDE, which creates, edits, builds and debugs Visual Basic .NET projects (Windows)
- .NET SDK – the
dotnettool that builds Visual Basic projects (Windows, macOS, Linux) - cscript and wscript – the Windows Script Host that runs VBScript (Windows)
- Microsoft Office – the Visual Basic for Applications editor and macros of Word, Excel and Access (Windows, macOS)
- twinBASIC – a modern compiler that reads Visual Basic 6 and VBA projects (Windows)
Developers
- dotnet/roslyn – the Visual Basic and C# compilers and their analysis APIs (C#, Visual Basic)
- dotnet/vblang – the language specification and the design proposals of Visual Basic (Markdown)
Reference
- Visual Basic Language Specification – the specification as Markdown, with the grammar
- Visual Basic documentation – Microsoft’s guide and language reference
- Language version history – the features each version of Visual Basic added
- VBA documentation – the Visual Basic for Applications language reference (Markdown)