Visual Basic for Beginners

A simple introduction to Visual Basic and how it works.

What is Visual Basic?

Visual Basic (VB) is a programming language created by Microsoft. It is known for being easy to learn, especially for beginners. Visual Basic lets you create Windows applications using simple, readable English-like commands.

Why Learn Visual Basic?

Your First Visual Basic Program

Here is a simple example written in VB.NET that prints a message on the screen:

Imports System

Module Program
    Sub Main()
        Console.WriteLine("Hello, Visual Basic!")
    End Sub
End Module
      

Common Visual Basic Commands

Example: Variables and Math

Module Program
    Sub Main()
        Dim a As Integer = 5
        Dim b As Integer = 3
        Dim result As Integer = a + b

        Console.WriteLine("The result is: " & result)
    End Sub
End Module
      

Beginner Example: If…Then Decision

Module Program
    Sub Main()
        Dim age As Integer = 16

        If age >= 18 Then
            Console.WriteLine("You are an adult.")
        Else
            Console.WriteLine("You are a minor.")
        End If
    End Sub
End Module
      

Beginner Example: Looping Through Items

Module Program
    Sub Main()
        Dim fruits() As String = {"Apple", "Banana", "Cherry"}

        For Each fruit In fruits
            Console.WriteLine("Fruit: " & fruit)
        Next
    End Sub
End Module
      

Beginner Example: Simple Function

Module Program
    Function AddNumbers(a As Integer, b As Integer) As Integer
        Return a + b
    End Function

    Sub Main()
        Dim result As Integer = AddNumbers(4, 6)
        Console.WriteLine("The total is: " & result)
    End Sub
End Module
      

How to Start Learning

  1. Download and install Visual Studio Community.
  2. Create a new "Console App (VB.NET)" project.
  3. Copy and paste the example code above.
  4. Press F5 to run your program!