Another VB WTF



  • <FONT color=#0000ff size=2>

    I was recently hired to finish up a VB application that 2 other "developers" had started. I was asked how long it would take to comeplete so I looked at the code and told them it would take longer than I first expected. I hope you all enjoy this little gem. 

     

    Dim</FONT><FONT size=2> c </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> Int16 = 1

    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> intAliasIDType </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Integer

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> stAliasIDNumber </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2> = </FONT><FONT color=#a31515 size=2>""

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>For</FONT><FONT size=2> c = 1 </FONT><FONT color=#0000ff size=2>To</FONT><FONT size=2> 4

    </FONT><FONT color=#0000ff size=2>   Select</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Case</FONT><FONT size=2> c

    </FONT><FONT color=#0000ff size=2>      Case</FONT><FONT size=2> 1 </FONT><FONT color=#008000 size=2>' 51 - SSN

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>         If</FONT><FONT size=2> stSSN = </FONT><FONT color=#a31515 size=2>""</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Or</FONT><FONT size=2> (bNameMatched = </FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>And</FONT><FONT size=2> stSSN = </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.tbSSN.Text) </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>            Exit</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Select

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>         End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If

    </FONT><FONT size=2>

             intAliasIDType = 51

             stAliasIDNumber = stSSN

             InsertAliasRecord(intDocnum, stAliasIDNumber, intAliasNameType, intAliasIDType)

    </FONT><FONT color=#0000ff size=2>      Case</FONT><FONT size=2> 2 </FONT><FONT color=#008000 size=2>' 38 - DL

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>         If</FONT><FONT size=2> stDL = </FONT><FONT color=#a31515 size=2>""</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Or</FONT><FONT size=2> (bNameMatched = </FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>And</FONT><FONT size=2> stDL = </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.tbDLNum.Text) </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>            Exit</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Select

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>         End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If

    </FONT><FONT size=2>

             intAliasIDType = 38

             stAliasIDNumber = stDL

             InsertAliasRecord(intDocnum, stAliasIDNumber, intAliasNameType, intAliasIDType)

          </FONT><FONT color=#0000ff size=2>Case</FONT><FONT size=2> 3 </FONT><FONT color=#008000 size=2>' 46 - UniqueID1</FONT>

    <FONT size=2></FONT><FONT color=#0000ff size=2>         If</FONT><FONT size=2> stUniqueID1 = </FONT><FONT color=#a31515 size=2>""</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Or</FONT><FONT size=2> (bNameMatched = </FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>And</FONT><FONT size=2> stUniqueID1 = </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.tbID1Text) </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>            Exit</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Select

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>         End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If

    </FONT><FONT size=2>

             intAliasIDType = 46

             stAliasIDNumber = stUniqueID1

             InsertAliasRecord(intDocnum, stAliasIDNumber, intAliasNameType, intAliasIDType)

    </FONT><FONT color=#0000ff size=2>      Case</FONT><FONT size=2> 4 </FONT><FONT color=#008000 size=2>' 40 - UniqueID2

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>         If</FONT><FONT size=2> stUniqueID2 = </FONT><FONT color=#a31515 size=2>""</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Or</FONT><FONT size=2> (bNameMatched = </FONT><FONT color=#0000ff size=2>True</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>And</FONT><FONT size=2> stUniqueID2 = </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.tbID2.Text) </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>            Exit</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Select

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>         End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>If

    </FONT><FONT size=2>

             intAliasIDType = 40

             stAliasIDNumber = stUniqueID2

             InsertAliasRecord(intDocnum, stAliasIDNumber, intAliasNameType, intAliasIDType)

    </FONT><FONT color=#0000ff size=2>   End</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Select

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Next</FONT><FONT size=2> c

    </FONT>


  • one step forwards, two steps back ...

    The for + swtich pattern seems to be a classic, but the reason is a real mystery to me.

    Like many programming WTF bad habits, this must come from some specific everyday real life reasoning, but I don't get this one. Any ideas ?

    Or it might come from a catastrophic book for beginners, in which case every copy must be burned along with its author.



  • I wish that the stupid VB6 guys would just stay the hell away from VB.NET.

     

    There's so much wrong with that that it's not funny. Of course, some moron will be along in short order blaming the language for the retard using it. 



  • What the hell.. there are too many things wrong with this.

    FYI: VB6 is my primary with C# being secondary (among a host of others).. it is the coder's fault, not the language.. someone can just as easily do this in .NET or Java (I've seen plenty of Java done by the North office that makes me want to puke)..



  • Refactored (pseudocode, I'm not a VB guy).  Did I miss anything?

     

    #define MAGIC_SSN 51
    #define MAGIC_DL  38
    #define MAGIC_ID1 46
    #define MAGIC_ID2 40

    foo = stSSN      , bar = Me.tbSSN.Text  , baz = MAGIC_SSN; DoIt(foo, bar, baz)
    foo = stDL       , bar = Me.tbDLNum.Text, baz = MAGIC_DL ; DoIt(foo, bar, baz)
    foo = stUniqueID1, bar = Me.tbID1.Text  , baz = MAGIC_ID1; DoIt(foo, bar, baz)
    foo = stUniqueID2, bar = Me.tbID2.Text  , baz = MAGIC_ID2; DoIt(foo, bar, baz)

    DoIt (foo, bar, baz):
      if foo = "" then return
      if bNameMatched then if foo = bar then return
      intAliasIDType = baz
      InsertAliasRecord(intDocNum, stAliasIDNumber, intAliasNameType, intAliasIDType)
      return
     



  • When I saw the subject line I thought it was another VB-bashing post. But it's not, just someone with brain damage who was let off his leash long enough to spit out a horrible chunk of code. I like how he totally makes sure that c is set to 1. Cuz sometimes the program needs to be told "I'm serious about starting off c = 1, so let's make it happen".



  • I don't know why I feel compelled to waste my time and yours pointing this out.. but the code is written in VB.NET, not VB6.  VB6 doesn't support initializers on variables declarations.



  • @GhostInAK said:

    I don't know why I feel compelled to waste my time and yours pointing this out.. but the code is written in VB.NET, not VB6.  VB6 doesn't support initializers on variables declarations.

    Well also VB6 doesn't have the "exit select" statement, the Int16 datatype, or support the  Func(x,y,z) syntax without an assignment either if we're going to point out the obvious.

     

    The structure just looks so much like the masses of bad VB6 code I've seen. Apologies to the 'author' if he isn't a migrated evil VB6 guy. He's just a plain ol' run of the mill evil guy.



  • The poor misguided person who wrote this was my company's IT Manager. They wanted a custom application so he decided to write it in secret and as usual when someone gets in over their head, they move along and leave a mess for the next person who comes along. Man, I love this job.



  • OMG!!! Is that duff's device implemented in VB?????!!!


Log in to reply