DEV Community

Rethabile Bridget Velelo
Rethabile Bridget Velelo

Posted on

3 Mistakes I made as a Visual Basic Developer (And what they actually taught me).

Let’s face it: Visual Basic (VB.NET) gets a lot of flak in the modern tech world. It’s often viewed as the "dinosaur" language, relegated to maintaining legacy enterprise software or ancient WinForms apps.

But here’s the truth: VB.NET is the unsung hero powering countless critical systems globally. When I first started writing it, I thought it was incredibly forgiving. As it turns out, that forgiveness was a trap.

Looking back at my early code, I made some absolute rookie mistakes that led to chaotic debugging sessions and production headaches. Here are three major mistakes I made as a VB developer, and how they actually made me a better engineer.

  1. The Trap of Silence: Relying on On Error Resume Next When you're new and a bug keeps crashing your app, On Error Resume Next feels like a magic wand. It literally tells the compiler, "Hey, if something breaks, just ignore it and keep moving."

VB.Net
' My rookie mistake
Public Sub ProcessData()
On Error Resume Next
Dim userData As String = FetchFromDatabase()
Dim score As Integer = Convert.ToInt32(userData) ' What if this is null?
DisplayScore(score)
End Sub

Why it was a mistake:
It didn't fix the bugs; it just hid the bodies. If the database returned a bad string, the application would silently skip the error, pass a broken default value down the line, and corrupt data further down the stack. Finding the root cause of a bug weeks later was an absolute nightmare.

The Lesson:
Structured exception handling exists for a reason. I learned to embrace Try...Catch...Finally blocks and properly log errors. Failing fast is always better than failing silently.

VB.Net
' The mature way
Public Sub ProcessData()
Try
Dim userData As String = FetchFromDatabase()
Dim score As Integer = 0

    If Integer.TryParse(userData, score) Then
        DisplayScore(score)
    Else
        Logger.LogWarning("Invalid user data format.")
    End If
Catch ex As SqlException
    Logger.LogError("Database connection failed", ex)
    ShowFriendlyErrorMessage()
End Try
Enter fullscreen mode Exit fullscreen mode

End Sub

  1. Leaving Option Strict Off By default, VB.NET is incredibly laid back about data types. If Option Strict is turned Off, the compiler will happily let you assign a string to an integer and try to convert it implicitly at runtime.

VB.Net
' With Option Strict OFF, this compiles perfectly fine:
Dim myText As String = "123"
Dim myNumber As Integer = myText
Why it was a mistake:
It breeds lazy programming and creates massive performance overhead because of implicit "boxing" and "unboxing." Worse, if myText accidentally becomes "123-abc", your app will blow up at runtime with an InvalidCastException.

The Lesson:
Turn Option Strict On and Option Explicit On at the very top of your files (or better yet, force it globally in your project settings).

VB.Net
Option Strict On
Option Explicit On

Dim myText As String = "123"
' Dim myNumber As Integer = myText ' <-- This now safely fails at COMPILE time!
Dim myNumber As Integer = Convert.ToInt32(myText) ' Safe and explicit
It forces you to write clean, intentional, and type-safe code, catching bugs before they ever hit production.

  1. Using Logical Operators Inherited from VB6 (And / Or) Coming into VB.NET, I assumed And and Or behaved exactly like && and || in C# or JavaScript.

VB.Net
' The Dangerous Mistake
If user IsNot Nothing And user.IsAdmin Then
GrantAccess()
End If
Why it was a mistake:
In VB.NET, And and Or do not short-circuit by default. They evaluate both sides of the expression no matter what. In the code above, if the user object is Nothing (null), the compiler still tries to check user.IsAdmin, resulting in a spectacular NullReferenceException.

The Lesson:
Always use AndAlso and OrElse for short-circuiting logical operations.

VB.Net
' The Safe Way
If user IsNot Nothing AndAlso user.IsAdmin Then
GrantAccess()
End If
With AndAlso, if the first condition is false, the compiler stops looking immediately, saving your app from crashing.

Conclusion: Respect the Legacy
Making these mistakes taught me that a programming language is only as dangerous as the constraints you put on it. Forcing discipline onto my VB.NET code made the transition to other languages like C# and TypeScript incredibly smooth later in my career.

Whether you are maintaining a legacy VB app or building internal tools, remember: keep your options strict, your errors caught, and your logic short-circuited!

Are you still maintaining any VB.NET apps? What's the weirdest language quirk that's ever caught you off guard? Let's talk in the comments!

Top comments (0)