Up until a couple years ago, a substantial amount of reporting in one division of a major corporation was done manually. Yes, the numbers were generated by automated systems, but the multiple pieces of proprietary software didn't cross-communicate, so reports were printed off, and manually error checked using the time-honored stare and compare algorithm. Although a WTF on its own, that's not really the fun part. One supervisor finally put forth the effort to fix the problem, creating a series of ASP classic webapps hosted on the company intranet to query the SQL servers that actually hosted the data, organize it, and do all the comparisons and error tests automatically. Sure, it was Q4 2007, but the information age had begun! The problem, of course, is that the original "developer" was nothing of the sort. He didn't actually know how to code in vbscript. Or, frankly, at all. Much of his work consisted of hitting Google, finding similar-appearing code and copy-pasting it into whatever his current project was. It is a testament, I suppose, to his diligence that most of those project did eventually work -- or at least look like they did. It's hard to tell.
My unenviable task, naturally, is to maintain this system. Wherein I mostly mean rebuild from scratch while preserving the original functionality (or, where the functionality wasn't ... well, functional, to fix it). I've been doing a lot of "fixing it" but sometimes it's hard to even tell what a block of code was supposed to do. Naturally, there's zero documentation and the only comments I've found so far are almost Zen in their lack of utility. Anti-patterns are the rule of the day. There are no named constants; magic numbers are simply hardcoded whenever they came in handy. And they come in handy a lot, since much of the data is moved around through giant arrays that are like the inbred cousins of object-oriented structure.
The creator of this mess was very fond of the for-case construct. But we've seen that before. So here's an example of what flow control "should" look like:
counter3 = -1
for tempswitch = 3 to 12
for counter = 0 to ubound(PreOutp, 2)
index = 0
counter2 = 0
if CInt(PreOutp(tempswitch, counter)) <> 0 AND counter < (ubound(PreOutp, 2) - 1) then
counter2 = counter
index = index + CInt(PreOutp(tempswitch, counter))
if CInt(PreOutp(tempswitch, counter2 + 1)) <> 0 then
do while (CInt(PreOutp(tempswitch, counter2)) <> 0) AND (PreOutp(0, counter) = PreOutp(0, counter2)) AND counter2 < (ubound(PreOutp, 2) - 1)
counter2 = counter2 + 1
if (PreOutp(0, counter) = PreOutp(0, counter2)) then index = index + CInt(PreOutp(tempswitch, counter2))
loop
end if
if (tempswitch = 4) or (tempswitch = 5) then
typeswitch = tempswitch - 3
else
typeswitch = tempswitch + 7
end if
end if
if ((index > 300) OR ((typeswitch <> 1) AND (typeswitch <> 2))) AND (counter2 > 0) then
counter3 = counter3 + 1
redim preserve Outp(4, counter3)
Outp(0, counter3) = typeswitch
Outp(1, counter3) = FormatDateTime(CDate(PreOutp(1, counter)), 3)
if counter <> (counter2 - 1) then
Outp(1, counter3) = DateAdd("s", (900 - CInt(PreOutp(tempswitch, counter))), Outp(1, counter3))
end if
Outp(2, counter3) = DateAdd("s", index, Outp(1, counter3))
Outp(3, counter3) = index
Outp(4, counter3) = PreOutp(0, counter)
end if
if counter2 > counter then counter = counter2
next
next
For the record, I don't have the foggiest notion what this was supposed to do.