My t_head t_hurts from t_looking at t_this t_code
While working on one of our legacy products today, I ran head first into this code:
Set cl_list = Cobj_LOR_CLAUSE.Contents
For t_int = cl_list.Count - 1 To 0 Step -1
Set cl_rec = cl_list.ItemByIndex(t_int)
If cl_rec.GetField("parameterized") = 1 Then
t_str = "XYZZYParamXYZZY#" & Trim$(Str$(t_int))
t_pos = 1
While t_pos > 0
t_pos = Instr(sql_stmt, t_str)
If t_pos > 0 Then
If Left$(cl_rec.GetField("operation"), 3) = "is " And _
Instr(cl_rec.GetField("operation"), "equal") <= 0 Then
new_val = fix_up_is_in(cl_rec.GetField("value"), _
Mid$(sql_stmt, t_pos - 1, 1) = "'")
Else
If cl_rec.GetField("operation") = "within last (days)" Then
t_date2 = App.CurrentDate
t_date = CStr(DateAdd("d", -1 * CInt(cl_rec.GetField("value")), CDate(t_date2)))
t_pos2 = Instr(t_pos + 1, sql_stmt, t_str)
sql_stmt = Left$(sql_stmt, t_pos - 1) & t_date & _
Mid$(sql_stmt, t_pos + Len(t_str), _
t_pos2 - t_pos - Len(t_str)) & t_date2 & _
Mid$(sql_stmt, t_pos2 + Len(t_str), _
Len(sql_stmt) - t_pos2 - Len(t_str) + 1)
Goto next_param
Else
If cl_rec.GetField("operation") = "within last (hours)" Then
t_date2 = App.CurrentDate
t_date = CStr(DateAdd("h", -1 * CInt(cl_rec.GetField("value")),
CDate(t_date2)))
t_pos2 = Instr(t_pos + 1, sql_stmt, t_str)
sql_stmt = Left$(sql_stmt, t_pos - 1) & t_date & _
Mid$(sql_stmt, t_pos + Len(t_str), _
t_pos2 - t_pos - Len(t_str)) & t_date2 & _
Mid$(sql_stmt, t_pos2 + Len(t_str), _
Len(sql_stmt) - t_pos2 - Len(t_str) + 1)
Goto next_param
Else
new_val = cl_rec.GetField("value")
End If
End If
End If
sql_stmt = Left$(sql_stmt, t_pos - 1) & new_val & _
Mid$(sql_stmt, t_pos + Len(t_str), _
Len(sql_stmt) - t_pos - Len(t_str) + 1)
End If
next_param:
Wend
End If
Next t_int
Holy string manipulation, Batman!
Martin Fowler says it well:
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
