Comprehensive collection of VB6 and VB.NET examples for developers
Visual Basic 6, a third-generation event-driven programming language launched by Microsoft in 1991, offers boundless possibilities for application development. Whether you aspire to create educational apps, financial tools, games, multimedia experiences, animations, or robust database applications, VB 6 empowers you to reach for the stars in your programming endeavors.
Explore a wealth of sample codes meticulously crafted by the vbtutor.net team; they serve as valuable references for your assignments and projects.
Build applications quickly with VB's intuitive drag-and-drop interface
Perfect language for those starting their programming journey
Create practical business and productivity tools
Millions of VB applications still power businesses worldwide
Unlock the power of Visual Basic with this comprehensive, hands-on guide that bridges the gap between classic VB6 and modern VB.NET programming. Whether you're maintaining legacy systems or developing cutting-edge Windows applications, this book gives you the knowledge, tools, and inspiration to succeed
Visual Basic Programming with Code Examples offers a unique dual-format approach, showcasing sample codes in both Visual Basic 6 (VB6) and VB.NET. This side-by-side presentation helps you understand the evolution of Visual Basic and empowers you to work confidently across both environments.
Whether you're a beginner or looking to refine your programming skills, this book simplifies learning through hands-on examples. Ideal for students, educators, and hobbyists.
Buy Now on Amazon Kindle EditionA simple Body Mass Index calculator with visual indicators.
Private Sub CalculateBMI()
Dim height As Double
Dim weight As Double
Dim bmi As Double
' Get user input
height = Val(txtHeight.Text) / 100 ' Convert cm to meters
weight = Val(txtWeight.Text)
' Calculate BMI
If height > 0 Then
bmi = weight / (height * height)
lblBMI.Caption = Format(bmi, "0.00")
' Display category
Select Case bmi
Case Is < 18.5
lblCategory.Caption = "Underweight"
lblCategory.ForeColor = vbBlue
Case 18.5 To 24.9
lblCategory.Caption = "Normal weight"
lblCategory.ForeColor = vbGreen
Case 25 To 29.9
lblCategory.Caption = "Overweight"
lblCategory.ForeColor = vbOrange
Case Else
lblCategory.Caption = "Obesity"
lblCategory.ForeColor = vbRed
End Select
Else
MsgBox "Please enter valid height", vbExclamation
End If
End Sub
This example demonstrates form controls, calculations, and conditional logic.
Connect to an Access database and display records.
Private Sub LoadData()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
' Initialize connection
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\mydb.mdb;"
conn.Open
' Create SQL query
sql = "SELECT * FROM Customers"
' Execute query
Set rs = New ADODB.Recordset
rs.Open sql, conn, adOpenStatic, adLockReadOnly
' Display data in listbox
lstCustomers.Clear
If Not rs.EOF Then
rs.MoveFirst
Do While Not rs.EOF
lstCustomers.AddItem rs!CustomerID & " - " & rs!CompanyName
rs.MoveNext
Loop
Else
MsgBox "No records found", vbInformation
End If
' Clean up
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
This example shows how to connect to a database and retrieve records using ADO.
Visual Basic remains a valuable skill despite newer languages because:
Test your Visual Basic skills with these practical exercises:
Create a program that converts between Celsius and Fahrenheit. The program should:
Formulas:
Fahrenheit = (Celsius × 9/5) + 32
Celsius = (Fahrenheit - 32) × 5/9
Create a simple contact management system with the following features:
Advanced: Add editing and deletion capabilities for existing contacts.
Dr. Liew Voon Kiong, the founder and webmaster of VBTutor.net, holds a Bachelor's Degree in Mathematics, a Master's Degree in Management, and a Doctorate in Business Administration (DBA) from the University of South Australia.
With a lifelong passion for programming and education, Dr. Liew has been actively involved in the software development and academic community for decades. In 1996, he launched the renowned Visual Basic Tutorial website, which has since become a top-ranked resource for Visual Basic learners around the world, attracting millions of visitors.
In addition to his online tutorials, Dr. Liew has authored multiple best-selling books on Visual Basic, including the popular title Visual Basic 6 Made Easy, published by Creativespace.com, an Amazon publishing platform. His work continues to empower students, hobbyists, and professionals to learn programming in an approachable and practical way.