“I recently started on a new contract,” Vedran R writes, “and the experience has been rather… interesting. The project I’ve been assigned to is a VB .NET 1.1 web application, and the code is rather… bad. Now, I know that developers make all kinds of compromises because of lack of time or experience but this is just… well, here’s some of the code.”

“Why fix the problem where it originates, it’s much simpler to handle it this way!”

sSql = GetSql(sTypeCurrency, sWHERE, sOrder)

If bGroup = True Then
    sSql = Replace(sSql, "WHERE  and", " WHERE ")
    sSql = Replace(sSql, "WHERE and", " WHERE ")
    sSql = Replace(sSql, "WHERE  AND", " WHERE ")
    sSql = Replace(sSql, "WHERE AND", " WHERE ")
    ...snip...
End If

"So how do you to determine if an object is null in JavaScript? Simple...

if (top.arrLisAdjCodEmp[f] != 0 && top.arrLisAdjCodEmp[f] + "" != "undefined")

... first we check if the object equals 0 and then we check if it not null by casting it to a string and comparing it to 'undefined'. Nice one!"

 

"Classes? We don't need no stinking classes!"

Private Function fWhere(ByVal bGroup As Boolean, ByVal lCodCompany As Integer, 
ByVal sCodAutonomy As String, ByVal sCodProvince As String, ByVal sCodArea As 
String, ByVal sCodDelegation As String, ByVal sDateFrom As String, ByVal sDateTo 
As String, ByVal iDate As Integer, ByVal sCodClients As String, ByVal sCodClientFrom 
As String, ByVal sCodClientTo As String, ByVal sDesClientFrom As String, ByVal 
sDesClientTo As String, ByVal sCodclientRange As String, ByVal iUte As Integer, 
ByVal iOrderEst As Integer, ByVal dOffer1 As Double, ByVal dOffer2 As Double, 
ByVal sCodGroup As String, ByVal sCodSubGroup As String, ByVal aDivision As 
Array, ByVal aCodTypoLicita As Array, ByVal aCodGroups As Array, ByVal 
aCodCompanies As Array) As String

 

"How to execute a „complicated“ SQL in a stored procedure? Piece of cake!"

DECLARE @QUERY AS VARCHAR(1000)

SET @QUERY = 'SELECT NUMTASK, YEARTASK, DATEOPEN '
SET @QUERY = @QUERY + 'from TaskStudio '
SET @QUERY = @QUERY + 'WHERE ( '
SET @QUERY = @QUERY + 'CODCOMPANY = ' + CONVERT(VARCHAR,@CODCOMPANY) + ' AND '
SET @QUERY = @QUERY + 'DATEOPENINGS = ''' + CONVERT(VARCHAR,(CONVERT(DATETIME,@ DATEOPENINGS,103))) + ''' AND '
SET @QUERY = @QUERY + 'CODCLIENT = ' + CONVERT(VARCHAR,@CODCLIENT) + ' AND '
SET @QUERY = @QUERY + 'OFFEREURO = ' + CONVERT(VARCHAR,@OFFEREUROVAR) 
SET @QUERY = @QUERY + ' ) '

PRINT (@QUERY)
EXEC (@QUERY)

 

"If the variable contains an empty string, then assign an empty string to the field; else assign the value of the variable to the field."

If sCompanyGroup = "" Then
  Field46 = ""
Else
  Field46 = sCompanyGroup
End If

 

"If the variable contains an empty string, don’t do anything; else don’t do anything."

If bResult = "" Then

Else

End If

 

"Here's a first class if."

If bGroup1 = 0 Then
  bGroup = False
ElseIf bGroup1 = 1 Then
  bGroup = True
ElseIf bGroup1 = 2 Then
  bGroup = True
EndIf

 

"More JavaScript. Is it a string or an integer?"

if (obj.value>="9000" && obj.value<=9999)

 

"Ugh, I love my job."

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!