VB.NET Basics

    Atul Kabra4 min readUpdated

    VB.NET (Visual Basic .NET) is a language that runs on the .NET platform, just like C#. It compiles to the same Intermediate Language and uses the same Base Class Library, so a VB.NET program can do anything a C# program can. Its syntax is wordier and uses keywords like Dim, End Sub, and Then instead of braces, which some beginners find readable. VB.NET still runs on modern, cross-platform .NET, though for new projects C# is the more widely used and actively evolving choice. Knowing VB.NET basics is useful because plenty of existing business applications are written in it.

    A minimal VB.NET program

    A VB.NET console app has an explicit module and a Sub Main:

    ' This is a comment in VB.NET (starts with a single quote).
    Module Program
        Sub Main()
            Console.WriteLine("Welcome to VB.NET!")
        End Sub
    End Module
    

    Notice there are no semicolons and no curly braces — blocks end with End Sub, End Module, and so on.

    Variables

    You declare variables with Dim (short for "dimension"), giving a name and a type with As:

    Dim age As Integer = 19          ' whole number
    Dim marks As Double = 84.5       ' number with a decimal
    Dim city As String = "Jalgaon"   ' text
    Dim isEnrolled As Boolean = True ' True or False
    
    Console.WriteLine(age)           ' 19
    Console.WriteLine(city)          ' Jalgaon
    

    VB.NET is statically typed: once a variable is As Integer, it stays an integer.

    Output and input

    Console.Write("Enter your name: ")    ' Write keeps the cursor on the same line
    Dim name As String = Console.ReadLine()
    
    ' & joins strings together (string concatenation).
    Console.WriteLine("Hello, " & name & "!")
    

    Console.ReadLine returns text. To work with it as a number, convert it:

    Console.Write("Enter your age: ")
    Dim input As String = Console.ReadLine()
    Dim age As Integer = Integer.Parse(input) ' text -> number
    Console.WriteLine("Next year: " & (age + 1))
    

    Operators

    Dim a As Integer = 10
    Dim b As Integer = 3
    Console.WriteLine(a + b)   ' 13
    Console.WriteLine(a - b)   ' 7
    Console.WriteLine(a * b)   ' 30
    Console.WriteLine(a \ b)   ' 3  integer division uses the BACKSLASH
    Console.WriteLine(a Mod b) ' 1  remainder
    

    In VB.NET, \ is whole-number division and / gives a decimal result, which is different from C#.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses

    Decisions and loops

    Dim score As Integer = 72
    
    ' If / ElseIf / Else uses 'Then' and ends with 'End If'.
    If score >= 75 Then
        Console.WriteLine("Distinction")
    ElseIf score >= 40 Then
        Console.WriteLine("Pass")
    Else
        Console.WriteLine("Try again")
    End If
    
    ' A For loop counts from 1 to 3.
    For i As Integer = 1 To 3
        Console.WriteLine("Attempt " & i)
    Next
    ' Output: Attempt 1 / Attempt 2 / Attempt 3
    

    VB.NET uses = for both comparison and assignment (the meaning is clear from context), which differs from C#'s ==.

    A simple class

    OOP works the same way conceptually as in C#:

    Public Class Student
        Public Property Name As String
        Public Property Marks As Integer
    
        Public Function Grade() As String
            If Marks >= 75 Then
                Return "Distinction"
            Else
                Return "Pass"
            End If
        End Function
    End Class
    

    Common mistakes

    • Using / for whole-number division. In VB.NET, / returns a Double. Use \ for integer division.
    • Forgetting End keywords. Every block (If, Sub, Function, Class) needs its matching End If, End Sub, etc.
    • Expecting ==. VB.NET uses a single = for comparison, unlike C#.
    • Mixing up & and + for strings. Prefer & to join strings; + can behave unexpectedly with mixed types.
    • Assuming VB.NET is outdated tech. It runs on the same modern .NET runtime as C#; for new work, though, C# has the larger community and faster language evolution.

    FAQ

    Is VB.NET the same as old Visual Basic 6? No. VB6 was a separate, pre-.NET product. VB.NET is a modern .NET language.

    Should a beginner pick VB.NET or C#? Either teaches the same .NET concepts. C# is the more common industry choice today, but VB.NET reads gently and is fine for learning.

    Keep learning

    Learn .NET languages with a local mentor in Jalgaon — join the waitlist for the Infoplanet .NET course at /courses/dotnet.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses
    Atul Kabra

    Founder, Infoplanet

    Atul Kabra founded Infoplanet in 2001 and has spent over two decades teaching programming — C, C++, Java, databases and more — to students across Maharashtra.

    Related guides