Over the years several different... people (I don't want to call them programmers), have written and maintained the code. This has resulted in dumb ass shit. Stuff I didn't know was even possible. Worse is that the first pass of the conversion was performed by an automated tool and a couple of intern level programmers who just blindly transposed the code from vb6 to vb.net. I'm not going to highlight oddities that were introduced by either of these though as that's just to be expected. No the code I'm going to show is legit code coded by supposed professionals.
This is one of my favs...
Dim stemp As String = "" Dim key As Integer For i As Integer = 1 To Strings.Len(sval) key = Asc(Strings.Mid(sval, i, 1)) If key >= 97 OrElse key <= 122 Then key = key - 32 stemp = stemp & Chr(key) Next sval = stemp
This would be just copy and pasted into sections of code when it had to be called. Not say wrapped into its own function that could be called or anything... nope, just thrown mid block of 800 lines of rambling code.
If you don't notice what's going on... I'm not surprised... you probably don't have the ASCII code sheet memorized. I only recognized because I happened to have looked at one earlier that day and went "wait a second... 97, that's 'a'..."
Yes, that's a 'ToUpper'... a function that already exists in vb.
Another one I love seeing is the lack of consistency. This will happen one right after the other. Like maybe it was written by two different people, both of whom didn't bother to look around themselves and notice that the previous line did the same thing just differently.
If Len(Trim(sTemp1)) >= 0 Then ''do stuff End If If Trim(sTemp2 & "") <> "" Then 'do stuff End If
But today, today I struck gold. I found the line of code that made me have to post here. Now note there is a util class that this project has that contains functions to manipulate strings. One of them is 'PadWithZeros', it takes in a string, a length, and an alignment value. It then pads zeros on the front or back of the string until the string is the length passed in. Pretty simple function, with so much potential! Like this gem:
Dim sval = StringUtil.FormatValue(CDbl(aRowArray.GetValue(lRowNum)) / CInt("1" & StringUtil.PadWithZeros("", 2)), StringUtil.FRM_AMT2)
Let me just focus in on that, to really show you the glory of it.
CInt("1" & StringUtil.PadWithZeros("", 2))
A part of my brain just ran down my nose.