Article 5MMFK CodeSOD: Without Any Padding

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?

otter-icon.png [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today! TheDailyWtf?d=yIl2AUoC8zAiC5iN_s8zjY
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments