As a reward for finishing up development on a project a couple weeks ahead of schedule, Jon was tasked with taking a look at some of the other systems his company develops to document and comment on the architecture and code. One system he came across had a unique way of managing database communications: each class was responsible for generating a SQL Script, "setting" it, and passing it to an execute function, which would then "fix" the script and execute it. You might be surprised how difficult it is to speculate and professionally explain the reason behind this ...

Function fncSetSQL(strSQL)
  Dim intCount, strLeft, strReMade
  intCount = Len(strSQL)
  Dim intSave

  Do While intCount <> 0
    strLeft = Left(strSQL, 1)
    If (strLeft = " ") Then
      strReMade = strReMade & "_"
    ElseIf(strLeft = "#") Then
      strReMade = strReMade & "~"
    Else
      strReMade = strRemade & strLeft
    End If
    intSave = Len(strSQL) - 1
    strSQL = Right(strSQL, intSave)
    intCount = intCount-1
  Loop
  fncSetSQL = strReMade
End Function


Function fncFixSQL(strSQL)
  Dim intCount, strLeft, strReMade, intSave
  intCount = Len(strSQL)
  
  Do While intCount > 0 
    strLeft = Left(strSQL, 1)
    If (strLeft = "_") Then
      strReMade = strReMade & " "
    ElseIf (strLeft = "~") Then
      strReMade = strReMade & "#"
    Else
      strReMade = strRemade & strLeft
    End If

    intSave = Len(strSQL) - 1
    strSQL = Right(strSQL, intSave)
    intCount = intCount - 1
  Loop
  fncFixSQL = strReMade
End Function
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!