Developed by students



  • At the company where I work (temporary gap-year job), there are several programs we use for automating various laborious procedures. These have been developed by various university engineering students over the years, and mostly work as well as can be expected.
    Unfortunately I am having several problems with the programs, preventing me from working properly (e.g. requiring the user to try to close it at least twice before anything actually closes).
    So, knowing a fair bit of programming, I had the crazy notion that maybe I could maybe fix some of the bugs, maybe even speed it up a little. So I delved into the source code...

    Here is a function from an obscure .vb file somewhere in the depths of the application (which basically extracts data from a couple of hundred xml files and puts it all into an excel spreadsheet).

    Public Sub DealWithTheBackgroundDataExtractionAndProcessingThread (ByVal state As BackgroundProcessingStates)
    
    	Try
    		ExtractDataThread.Abort()
    	Catch
    		Exit Sub
    	End Try
    
    	If BackgroundProcessingState = BackgroundProcessingStates.ProcessingOff Then
    		MotherForm.DefInstance.BPOnMenuItemButton.Checked = False
    		MotherForm.DefInstance.BPPartialMenuItemButton.Checked = False
    		MotherForm.DefInstance.BPOffMenuItemButton.Checked = True
    	ElseIf BackgroundProcessingState = BackgroundProcessingStates.ProcessingPartial Then
    		MotherForm.DefInstance.BPOnMenuItemButton.Checked = False
    		MotherForm.DefInstance.BPPartialMenuItemButton.Checked = True
    		MotherForm.DefInstance.BPOffMenuItemButton.Checked = False
    	ElseIf BackgroundProcessingState = BackgroundProcessingStates.ProcessingOn Then
    		MotherForm.DefInstance.BPOnMenuItemButton.Checked = True
    		MotherForm.DefInstance.BPPartialMenuItemButton.Checked = False
    		MotherForm.DefInstance.BPOffMenuItemButton.Checked = False
    	End If
    
    	If BackgroundProcessingState = BackgroundProcessingStates.ProcessingOff Or AnalysisInProcess Then
    		Exit Sub
    	End If
    
    	ExtractDataThread = New System.Threading.Thread(AddressOf BackgroundDataExtraction)
    	ExtractDataThread.Start()
    
    End Sub
    

    This function is called by just about every gui-related function in the program, most of the time with the parameter (which you may notice is completely ignored) sent as the global variable BackgroundProcessingState. This global variable is incidentally never initialized, so is always set to whatever enumerates to 0...

    TRWTF is the exporting procedure itself. The boss asked for a nice tag based system, where cells in excel are given names such as R_FLC_0_64_55 to indicate exactly what data needs to be put there; each underscore delimited element is a setting from the measurement.
    Because of the dynamic nature of these tags, only the elements could be hard coded into the program; each tag must be read from the spreadsheet and deconstructed. How do you get a list of all cell names in a workbook? Easy, you get the user to enter top left and bottom right 'coordinates' (without any explanation as to what they are for) and search every cell in that range until you finds one with a name. Gah!

    Here is another one, this time from the wonderful language that is Sax Basic. This was supposed to be a set of macros that takes a whole load of measurements over the course of a day, analyses them, then exports the data to excel.
    To be fair, the program was not finished (it is my job to complete rewrite it), but somebody obviously didn't quite think through their methodology...

    If MeasnumberMax >= 1 Then
    'Thinking about this perhaps we should have done something with array depth to save a lot of code down here
    'hSheet.Cells(SerialFull, ReportLocation1Full).Value = 'need to save serial number
    hSheet.Cells(ReportLocation1Full, xLocationFull).Value = ReportLocation1XMax
    hSheet.Cells(ReportLocation1Full, yLocationFull).Value = ReportLocation1YMax
    hSheet.Cells(ReportLocation1Full, frequencyFull).Value = ReportLocation1PeakF
    hSheet.Cells(ReportLocation1Full, amplatudeFull).Value = ReportLocation1PeakA
    End If
    If MeasnumberMax >= 2 Then
    'hSheet.Cells(SerialFull, (ReportLocation1Full + 1)).Value = 'need to save serial number
    hSheet.Cells((ReportLocation1Full + 1), xLocationFull).Value = ReportLocation2XMax
    hSheet.Cells((ReportLocation1Full + 1), yLocationFull).Value = ReportLocation2YMax
    hSheet.Cells((ReportLocation1Full + 1), frequencyFull).Value = ReportLocation2PeakF
    hSheet.Cells((ReportLocation1Full + 1), amplatudeFull).Value = ReportLocation2PeakA
    End If
    If MeasnumberMax >= 3 Then
    'hSheet.Cells(SerialFull, (ReportLocation1Full + 2)).Value = 'need to save serial number
    hSheet.Cells((ReportLocation1Full + 2), xLocationFull).Value = ReportLocation3XMax
    hSheet.Cells((ReportLocation1Full + 2), yLocationFull).Value = ReportLocation3YMax
    hSheet.Cells((ReportLocation1Full + 2), frequencyFull).Value = ReportLocation3PeakF
    hSheet.Cells((ReportLocation1Full + 2), amplatudeFull).Value = ReportLocation3PeakA
    End If
    If MeasnumberMax >= 4 Then
    'hSheet.Cells(SerialFull, (ReportLocation1Full + 3)).Value = 'need to save serial number
    hSheet.Cells((ReportLocation1Full + 3), xLocationFull).Value = ReportLocation4XMax
    hSheet.Cells((ReportLocation1Full + 3), yLocationFull).Value = ReportLocation4YMax
    hSheet.Cells((ReportLocation1Full + 3), frequencyFull).Value = ReportLocation4PeakF
    hSheet.Cells((ReportLocation1Full + 3), amplatudeFull).Value = ReportLocation4PeakA
    End If
    If MeasnumberMax >= 5 Then
    'hSheet.Cells(SerialFull, (ReportLocation1Full + 4)).Value = 'need to save serial number
    hSheet.Cells((ReportLocation1Full + 4), xLocationFull).Value = ReportLocation5XMax
    hSheet.Cells((ReportLocation1Full + 4), yLocationFull).Value = ReportLocation5YMax
    hSheet.Cells((ReportLocation1Full + 4), frequencyFull).Value = ReportLocation5PeakF
    hSheet.Cells((ReportLocation1Full + 4), amplatudeFull).Value = ReportLocation5PeakA
    End If
    If MeasnumberMax >= 6 Then
    'hSheet.Cells(SerialFull, (ReportLocation1Full + 5)).Value = 'need to save serial number
    hSheet.Cells((ReportLocation1Full + 5), xLocationFull).Value = ReportLocation6XMax
    hSheet.Cells((ReportLocation1Full + 5), yLocationFull).Value = ReportLocation6YMax
    hSheet.Cells((ReportLocation1Full + 5), frequencyFull).Value = ReportLocation6PeakF
    hSheet.Cells((ReportLocation1Full + 5), amplatudeFull).Value = ReportLocation6PeakA
    End If
    

    Basically, the previous student was expecting the user to enter X and Y coordinates (not cell references) for each of the six measurements. This kind of code was all through the macro, first for just checking all the cells exist, then that they are empty, and finally for writing the data to them (as shown).
    Well, so long as it works (I hear you say)... WRONG! The actual testing procedure can be anything up to 30 separate results in one batch!
    Judging by the comment, I assume he realised his mistake before it was too late; I dread to think what I would have done if this file was five times larger than it already is...
    I want to cry.



  • Just be glad he realized he was over his head and aborted before he made things worse-- and that it's obvious it doesn't work. It's ten times worse when you don't find such idiotic logic in pre-existing code until you are trying to figure out "Why the hell did something just drop the wrong table?"


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.