📘
Visual Basic .NET
OOP Tutorial
Learn Classes, Inheritance & Email Validation
![]() |
Visual Basic 2010 OOP |
Object-Oriented Programming (OOP) has revolutionized how Visual Basic (VB) applications are built, transforming traditional procedural code into modular, reusable, and scalable software. In this post, you’ll learn how OOP is implemented in Visual Basic .NET, with a hands-on project to validate email formats.
🧠 What Is OOP?
OOP (Object-Oriented Programming) is a programming paradigm centered around the concept of objects, which contain both data (properties) and behaviors (methods). VB.NET is a fully OOP language, allowing you to:
-
Encapsulate logic into classes.
-
Reuse code via inheritance.
-
Customize behavior using polymorphism.
✅ Four Main OOP Concepts in VB.NET
-
Abstraction
Hide complexity by modeling real-world entities as objects. -
Encapsulation
Keep data safe by restricting access and grouping with related behaviors. -
Polymorphism
Use the same method name across different objects, with different behavior. -
Inheritance
Reuse logic by deriving new classes from base classes.
🧱 OOP in Action: Email Format Validator in VB.NET
Let’s build a simple Windows Forms application that checks if a user-entered email address is in valid format.
👨🏫 Project Overview
-
Name: EmailFormatValidation
-
Platform: Visual Basic 2010 (.NET Framework)
-
Goal: Validate the presence of
@
and.
in an email address.
🖥️ Form Design
Control Type | Name | Text |
---|---|---|
Label | Label1 | Name |
Label | Label2 | |
TextBox | TxtName | [empty] |
TextBox | TxtEmail | [empty] |
Button | BtnValid | Validate E-mail |
✍ VB.NET Code Example
Private Sub BtnValid_Click(sender As Object, e As EventArgs) Handles BtnValid.Click
Dim X As Integer = TxtEmail.Text.IndexOf("@")
If X >= 1 Then
Dim Y As Integer = TxtEmail.Text.IndexOf(".", X)
If Y < 1 Then
MsgBox("Invalid E-mail Address")
Else
MsgBox("Valid E-mail Address Format")
End If
Else
MsgBox("Invalid E-mail Address")
End If
End Sub
✅ Explanation:
-
IndexOf("@")
: Checks if '@' exists and is not at the first position. -
IndexOf(".", X)
: Ensures '.' comes after '@'. -
Shows success or error message based on these conditions.
🎓 Homework / Practice Task
-
Design this app in Visual Basic 2010 and test various input cases.
-
Explore what happens when the email format is partially correct.
-
Try extending it to use Regular Expressions for better validation.
🧩 OOP Lesson Index
🔹 Classes Introduction [Source code example - ms access development]
🔹 Properties & Methods
🔹 Sub vs. Function
🔹 Overloading & Inheritance
🔹 Access Modifiers
🔹 Real OOP Project: Email TextBox Control
🧲 Final Notes
Visual Basic .NET gives you full access to OOP principles, making your applications easier to maintain, debug, and extend. Whether you're validating inputs or building full-scale enterprise apps, OOP is the backbone of clean and professional VB.NET development.
🧼 Github Repo VB.NET-OOP
Clone/Contribute https://github.com/facebookegypt/VB.NET-OOP.git
♥ Here are some online Visual Basic lessons and courses: