Some time ago, Will started a new job- a four month contract to take an old, ugly DOS application and turn it into a new, shiny VisualBasic 6 application. "And," the new boss explained, "the new program is almost done anyway. It's just that the last guy left, so we need someone to take it over the finish line."

A key feature was that it needed to be able to fetch PDF files stored on a shared network drive. The order numbers were serialized, but the PDFs themselves were organized by year, creating file paths like I:\ORDLOG\2007\172.pdf. Now, in this particular block of code, one had access to both the ordnum and the ordyear, so constructing this path could be a trivial exercise. The previous developer did not take the trivial path, though.

Select Case ordnum Case ordnum >= 18000 pdfstring = "I:\ORDLOG\2014\" + ordnum + ".pdf" Case ordnum <= 17999 And ordnum >= 16500 pdfstring = "I:\ORDLOG\2013\" + ordnum + ".pdf" Case ordnum <= 16499 And ordnum >= 15800 pdfstring = "I:\ORDLOG\2012\" + ordnum + ".pdf" ' ..........repeat for many lines to come End Select

So, the previous developer went through every year, identified the lowest and highest order number of that year, and then manually built a switch statement to decide with year that order number belonged to. Again, I want to stress, this block of code had access to an ordyear variable which contained the year information. Will replaced this entire statement with the more obvious solution.

But honestly, that's not the WTF. They're porting a DOS app to VB6 in 2014. The VB6 IDE hit end-of-life in 2008. While the VB6 runtime will be supported until the heat death of the universe, because Microsoft never breaks backwards compatibility, it's hard to develop code in a language where the only tool that can compile it hasn't been officially supported for six years. Speaking from experience supporting VB6 apps circa 2008, it was already difficult to get it actually working reliably on any relatively modern version of Windows aside from the most basic configurations. It got so bad that one of my main applications could only be built on one computer which had Windows Update disabled, because any attempt to do fresh installs of VB6 just failed outright.

VB6 and seeing 2014 in the code makes me hope that this story isn't from 2014, and instead they were future proofing the code and just predicting what orders they'd have in each year, because that's less awful, I think.

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