Visual Basic Tutorial for Beginners: Learn VB6 Step by Step
What Is Visual Basic?
Visual Basic is a programming language and development environment from Microsoft, first released in 1991. Its design goal was simple: let people who weren't professional programmers build real Windows applications. Drag a button onto a form, double-click it, write a few lines of code, run it.
That accessibility made VB the most popular Windows development tool of the 1990s. Versions 1 through 6 (1991–1998) defined what "Visual Basic" means to most people. Visual Basic 6 — the version this tutorial covers — became the most widely deployed development tool of its era and is still running mission-critical software today.
The Visual Basic Family Tree
"Visual Basic" actually refers to several related but distinct things. Knowing which one you're dealing with matters:
| Variant | Released | Status in 2026 | Where You'd See It |
|---|---|---|---|
| Visual Basic 1.0–6.0 | 1991–1998 | Unsupported but still runs | Legacy Windows desktop apps |
| VB.NET | 2002–today | Fully supported | Modern .NET applications |
| VBA (Visual Basic for Applications) | 1993–today | Actively maintained | Excel, Access, Word, Outlook macros |
| VBScript | 1996–today | Deprecated, being phased out | Windows automation, Classic ASP |
This tutorial focuses on Visual Basic 6 (VB6) — the syntax and concepts cover ~95% of what you need to know for VB6, VBA, and to a large extent VB.NET. Skills transfer naturally between them.
Why VB6 Skills Still Matter
Three honest reasons to learn VB in 2026:
- Massive legacy installed base. Estimates suggest hundreds of millions of lines of VB6 code still run in production worldwide. Major banks, insurance companies, factories, and government agencies have core systems written in VB6. Replacing them is expensive, so they hire developers to maintain them — at premium rates.
- VBA is everywhere. Every Microsoft Office installation includes VBA. Excel macros, Access database forms, Word document automation, Outlook scripts — these are still core tools in finance, accounting, operations, and analytics roles. The syntax is essentially VB6.
- Programming fundamentals. VB's visual IDE, gentle syntax, and immediate feedback make it the easiest way to learn programming concepts. Variables, loops, conditionals, events, classes — once you understand them in VB, picking up Python or C# is easy.
Visual Basic vs. Modern Languages
Honest comparison if you're deciding what to learn:
| If your goal is... | Best language | Why |
|---|---|---|
| Learn programming for the first time | Python or VB | Both are forgiving; VB has the friendlier IDE |
| Build modern Windows desktop apps | C# with WPF or .NET MAUI | Microsoft's primary investment |
| Automate Microsoft Office | VBA (Visual Basic) | Built into every Office install |
| Maintain legacy enterprise apps | VB6 | Unique skill, premium pay |
| Build web applications | JavaScript / Python / Ruby | VB doesn't target the web |
| Cross-platform (Windows + Mac + Linux) | Python / Java / C# | VB is Windows-only |
Prerequisites
None. Visual Basic was specifically designed for beginners. You need:
- A Windows computer (Visual Basic is Windows-only)
- Optionally, the Visual Basic 6 IDE if you have access to it, or Visual Studio Community (free) for VB.NET
- For VBA practice: any version of Microsoft Excel — press Alt+F11 to open the VBA editor
Your First Visual Basic Program
The simplest possible VB program. In a Form's code window:
Private Sub Form_Load() MsgBox "Hello, Visual Basic!" End Sub
Run the form. A message box pops up. That's a complete program.
Variables and Data Types
Unlike VBScript (everything is a Variant), Visual Basic uses explicit data types:
Dim name As String Dim age As Integer Dim salary As Double Dim isActive As Boolean name = "Alice" age = 30 salary = 55000.50 isActive = True MsgBox name & " is " & age
Common types you'll use constantly:
| Type | Holds | Range |
|---|---|---|
String | Text | Up to 2 billion characters |
Integer | Whole number | -32,768 to 32,767 |
Long | Big whole number | ±2.1 billion |
Single | Decimal (low precision) | ±3.4 × 10³⁸ |
Double | Decimal (high precision) | ±1.8 × 10³⁰⁸ |
Currency | Money | ±922 trillion (4 decimal places) |
Boolean | True or False | True / False |
Date | Date and time | 1/1/100 to 12/31/9999 |
Variant | Anything | Any of the above |
Option Explicit at the top of every module. It forces you to declare every variable with Dim, catching typos before they become bugs.
Control Flow: If, Select, Loops
If statements
Dim hour As Integer hour = Hour(Now) If hour < 12 Then MsgBox "Good morning" ElseIf hour < 18 Then MsgBox "Good afternoon" Else MsgBox "Good evening" End If
Select Case
Dim grade As Integer grade = 85 Select Case grade Case 90 To 100: MsgBox "A" Case 80 To 89: MsgBox "B" Case 70 To 79: MsgBox "C" Case Else: MsgBox "Below C" End Select
For loops
Dim i As Integer For i = 1 To 10 Debug.Print "Counter: " & i Next i ' For Each loops over collections Dim ctrl As Control For Each ctrl In Me.Controls Debug.Print ctrl.Name Next ctrl
Do loops
Dim count As Integer count = 0 Do While count < 5 Debug.Print count count = count + 1 Loop
Subs and Functions
Two ways to organize code:
' Sub: does something, returns nothing Public Sub Greet(person As String) MsgBox "Hello, " & person End Sub Call Greet("Alice") ' Function: returns a value Public Function Multiply(a As Double, b As Double) As Double Multiply = a * b End Function Dim result As Double result = Multiply(6.5, 4)
Working with Forms and Controls
Visual Basic's killer feature is its drag-and-drop form designer. You drag controls (buttons, text boxes, labels) onto a form, set their properties, and write code that runs when events happen.
' This runs when a button named cmdSubmit is clicked Private Sub cmdSubmit_Click() Dim userName As String userName = txtName.Text If userName = "" Then MsgBox "Please enter your name", vbExclamation txtName.SetFocus Exit Sub End If lblGreeting.Caption = "Hello, " & userName End Sub ' This runs when the form first loads Private Sub Form_Load() Me.Caption = "My First VB App" txtName.Text = "" txtName.SetFocus End Sub
Common VB Controls You'll Use
| Control | Purpose | Common Properties |
|---|---|---|
Label | Display read-only text | Caption, ForeColor |
TextBox | User input field | Text, MaxLength |
CommandButton | Clickable button | Caption, Default |
CheckBox | Yes/no option | Value, Caption |
OptionButton | Radio button (groupable) | Value, Caption |
ListBox | Multi-line selection list | List, ListIndex |
ComboBox | Dropdown list | List, Text, Style |
Image / PictureBox | Display images | Picture, Stretch |
Timer | Run code on interval | Interval, Enabled |
Frame | Group related controls | Caption |
Working with Files
Classic VB file I/O uses the Open statement:
' Read a text file line by line Dim fileNum As Integer Dim line As String fileNum = FreeFile Open "C:\data\input.txt" For Input As #fileNum Do Until EOF(fileNum) Line Input #fileNum, line Debug.Print line Loop Close #fileNum ' Write to a file fileNum = FreeFile Open "C:\output\result.txt" For Output As #fileNum Print #fileNum, "First line" Print #fileNum, "Second line" Close #fileNum
Database Access (ADO)
Visual Basic's most common real-world use: building forms over a database. The classic approach uses ADO (ActiveX Data Objects):
Dim conn As New ADODB.Connection Dim rs As New ADODB.Recordset conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\app.mdb" rs.Open "SELECT * FROM Customers WHERE Country = 'France'", conn Do Until rs.EOF Debug.Print rs.Fields("CustomerName").Value rs.MoveNext Loop rs.Close conn.Close
Common Beginner Mistakes
1. Forgetting Option Explicit
Without it, VB silently creates a new variable when you typo. Set it once in Tools → Options → "Require Variable Declaration" so every new module has it automatically.
2. Confusing = and Set
Regular variables use =. Object variables need Set:
' Wrong: form2 = New Form2 ' Right: Set form2 = New Form2
3. Not handling Nothing/Null
Database fields can be Null. Trying to assign Null to a non-Variant variable crashes. Use Nz() in Access or IsNull():
If Not IsNull(rs.Fields("Email").Value) Then email = rs.Fields("Email").Value End If
4. Memory leaks from not releasing objects
Always release object variables when done:
Set rs = Nothing Set conn = Nothing
5. Hard-coding paths
Don't write "C:\Users\Alice\..." in your code. Use App.Path for the application's own folder, or environment variables.
Complete Learning Path
The 24 chapters are organized into 6 logical parts. Work through them in order if you're new — you can jump if you have specific gaps.
Part I — Introducing Visual Basic (Chapters 1–4)
Part II — Coding the Details (Chapters 5–8)
Part III — Putting Code to Work (Chapters 9–12)
Part IV — Programming with Data (Chapters 13–16)
Part V — Sprucing Up Programs (Chapters 17–20)
Part VI — Advancing Visual Basic Applications (Chapters 21–24)
Visual Basic Cheat Sheet
| Task | Code |
|---|---|
| Show a message | MsgBox "Hello" |
| Get user input | name = InputBox("Your name?") |
| Concatenate | full = first & " " & last |
| Current date | today = Date |
| Current time | now_ = Now |
| Format number | Format(value, "#,##0.00") |
| Convert to number | num = CDbl(txtAmount.Text) |
| Convert to string | str = CStr(salary) |
| String length | n = Len(myString) |
| Substring | part = Mid(s, 5, 10) |
| Replace text | new = Replace(old, "a", "b") |
| Open form | Form2.Show |
| Close form | Unload Me |
| End program | End |
| Wait | Sleep 1000 ' needs API declaration |
Frequently Asked Questions
Is Visual Basic still used in 2026?
VB6 is no longer supported by Microsoft, but a huge installed base still runs in production — banks, insurance companies, manufacturing plants, and government systems. VB.NET (the modern successor) is fully supported in Visual Studio. VBA is still actively used in every Microsoft Office application.
Should I learn VB6, VB.NET, or VBA?
VBA if you automate Office (Excel, Access). VB.NET for new Windows desktop apps. VB6 only if you maintain legacy applications. The syntax is similar enough that learning one teaches you most of the others.
Where can I download Visual Basic 6?
Microsoft no longer sells VB6. Existing license holders can use it, and it does install on Windows 11 with some compatibility tweaks. For learning Visual Basic syntax, modern Visual Studio Community edition (free) supports VB.NET which uses similar syntax.
Is Visual Basic hard to learn?
Visual Basic was specifically designed to be easy. Syntax reads like English, the IDE has drag-and-drop form design, and you see your application running in seconds. It's one of the most beginner-friendly languages ever created.
What's the difference between VB6 and VB.NET?
VB6 (1998) is a self-contained legacy language for Windows desktop apps. VB.NET (2002) runs on the .NET Framework, has full object orientation, and uses modern programming patterns. Code from VB6 doesn't run directly in VB.NET — Microsoft provides upgrade tools but they require manual review.
Can I get a job with just Visual Basic skills?
Yes, in specific niches. VB6 maintenance jobs exist at large enterprises with legacy systems. VBA developers are in demand for Excel/Access automation in finance, accounting, and operations roles. VB.NET jobs are less common than C# but still exist.
Is VBA the same as Visual Basic?
VBA (Visual Basic for Applications) is a subset of Visual Basic that runs inside Microsoft Office and other host applications. The syntax is nearly identical to VB6. Skills transfer directly — if you know one, you can read and modify the other immediately.
How long does it take to learn Visual Basic?
Basic VB syntax: a few days. Building a complete Windows form application: 2–4 weeks. Confident with database access, advanced controls, and code organization: 2–3 months.
Start Chapter 1: Visual Basic at Work →Last updated: April 25, 2026.