CodeSOD: Without Any Padding
by Remy Porter from The Daily WTF on (#5MMFK)
Years ago, Aleshia W started a job in a VB.Net shop. There's a lot I could say about those kinds of environments, but I'd really just be padding out the article, so let's just get right to the code- which pads out a Year string.
Protected Function YearPadText(ByVal val As String) As String Dim valLen As Integer valLen = val.Len Select Case valLen Case 1 val = val + " " Case 2 val = val + " " Case 3 val = val + " " Case 4 val = val + " " Case 5 val = val + " " Case 6 val = val + " " Case 7 val = val + " " Case 8 val = val + " " Case 9 val = val + " " Case 10 val = val + " " Case 11 val = val + " " Case 12 val = val + " " Case 13 val = val + " " Case 14 val = val + " " End Select Return valEnd Function
You'll be unsurprised to learn that VB.Net has several different built-in ways of accomplishing this task, rendering this code unnecessary. One could complain that this code doesn't handle the situation when a year string is longer than 15 characters, but that raises a question: why would your year string be longer than 15 characters?
[Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!