Naming procedure line labels

I recently worked on improving a VB6 application, and as part of the task, I decided to "clean up" the way procedures used line labels.

While programmers usually use pretty descriptive (and often unique) names for procedure line labels, our preference has always been to stick to naming them exactly the same, irrespective of the procedure they're in.

Take this example:

Public Sub HideForm(ByRef F As Form)
   On Error GoTo Me_Fail
   Dim C As Integer, Loaded As Boolean
   C = Forms.Count
   With F
      Do Until C = 0
         If Forms(C - 1).Name = .Name Then
            Loaded = True
         End If
         C = C - 1
      Loop
      If Loaded Then
        .Hide
      End If
   End With
Me_Exit:
   Exit Sub
Me_Fail:
   Alert "Application", "HideForm", Err.Number, Err.Description, ERROR.FATAL
   Resume Me_Exit
End Sub

This approach simplifies the procedure creation process because each procedure gets "Me_Exit" and "Me_Fail" as the two standard labels which get branched to, as part of the error handling logic. It's also easy to remember, because every procedure has the same two generic labels.

I have been doing this for years but it appears that I'm in the minority, as most VB source code that I've seen tends to use procedure line label names which vary from procedure to procedure. This is unnecessary as Visual Basic won't let you use the "Goto" statement to branch outside of a procedure anyway.

While some VB developers might argue that there is sometimes a need for more than just the two error handling labels I mentioned above, I'd say that if you think so, then you probably need to think a bit more about your code design.

Due to the large volume of spam, comments are disabled. If you have anything to say, please feel free to contact me directly.

About the author

Ivan's mugshotIvan Lutrov is the owner of Lutrov Interactive. He creates cost effective business websites that are simple, engaging and very easy to use. When not busy working on client and personal projects, he's into photography, fishing, cricket, tennis, music from the 70s, cooking, good wine, and apparently knows "way too much" about movies. He tells it like it is, whether you like it or not. Subscribe to the Lutrov Interactive feed via RSS and follow Ivan on Twitter.