Stop treating VB.
The biggest offender in my early code was the On Error Resume Next crutch. It’s basically a "hide the bodies" command. It doesn't fix your logic; it just suppresses the symptoms.
' 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 SubIf that database call returns a null or a malformed string, the app just sails right through with a corrupted default value. You won't see an error until three modules later when the data state is completely nonsensical. I eventually moved to structured exception handling and strict validation because failing fast is always better than failing silently.
' 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
End SubThen there is the Option Strict issue. If you leave Option Strict Off, you are essentially inviting runtime InvalidCastException errors into your life. The compiler becomes way too relaxed about implicit conversions.
' With Option Strict OFF, this compiles perfectly fine:
Dim myText As String = "123"
Dim myNumber As Integer = myTextThis is a performance killer due to implicit boxing/unboxing, and it's a total safety hazard. I now force Option Strict On and Option Explicit On at the project level. It forces you to be intentional.
Option Strict On
Option Explicit OnDim 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
Finally, don't fall into the VB6 logical operator trap. I spent way too much time wondering why my null checks weren't working. In VB.NET, using And or Or doesn't short-circuit.
' The Dangerous Mistake
If user IsNot Nothing And user.IsAdmin Then
GrantAccess()
End IfIn the snippet above, even if user is Nothing, the compiler evaluates user.IsAdmin anyway, triggering a NullReferenceException. You have to use AndAlso and OrElse to get the short-circuiting behavior you expect from C# or JS.
' The Safe Way
If user IsNot Nothing AndAlso user.IsAdmin Then
GrantAccess()
End If