Jeff C. was hired as an exterminator. The "big rewrite" had a lot of "big bugs" that needed to be eliminated, which was somewhat ironic, as the big rewrite was commissioned to eliminate a lot of "little bugs" that found their way into the original system over the years.

A product of neglect and abuse, the original system had become a crazy nightmare of Classic ASP pages. Nothing fully worked, but things half-worked half the time. The big rewrite yielded exactly the same thing, but in VB.NET. There have been talks about rewriting the rewrite, but in the mean time, Jeff's day-to-day involves toiling in code like this:

Private Function Doubleize(ByVal StrVal As String) As Double
    Dim i, j, k As Integer
    Dim trimmedStr As String
    Dim isDecimal As Boolean = True
    k = 0
    trimmedStr = LTrim(RTrim(StrVal))
    For i = 1 To Len(trimmedStr)
        j = Asc(Mid(trimmedStr, i, 1))
        If Not (j = 46 OrElse (i = 1 AndAlso (j = 43 OrElse j = 45)) _
	   OrElse (j >= 48 AndAlso j <= 57)) Then
            isDecimal = False
            k = i
            Exit For
        End If
    Next i
    If isDecimal AndAlso Len(trimmedStr) > 0 Then
        Return Math.Round(CDbl(trimmedStr), 4)
    ElseIf k > 1 Then
        Return Math.Round(CDbl(Mid(trimmedStr, 1, k - 1)), 4)
        Return 0
    End If
End Function

"In case it's not obvious," Jeff writes, "the function turns strings into numbers (usually zero). There are at least four different-but-mostly-similar instances of this function throughout the project and, in the entire codebase, this function was used around fifty times. In virtually every usage, it was called multiple times like this."

ReasonStr = ReasonStr & _
   "Changed Unit Weight (" & _
   CStr(Doubleize(CStr(Doubleize(UnitWeightTextBox.Text) - InvItem_UnitWeight))) & _
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!