• (cs) in reply to Alex Papadimoulis

    It's an example of Structured Programming (namely, Encapsulation): VB6-in-VB.Net! (Much like the examples of only-modified-enough-to-compile C-to-C++ or C-to-PHP conversions I've seen, some of which were wtfs in their own right.)

    Usually happens when someone reads something about the new language being such a huge improvement over the old, and gives a bitter young hacker a week to do it (because it's the same language, only better!).

  • Chris F (unregistered) in reply to Ken

    Well, I tried this and have been fixing errors ever since.  It reaches the VS.Net maximum error limit (a few hundred), so I don't know the exact number, but I would guess it's easily in the thousands considering the amount that I have fixed so far.

    Truly amazing.

    About this code: As you can probably guess, the original author had no concept of an isolated data layer.  He would simply drag the SqlConnection component on to every form when he needed to hit the DB.  If he needed to use more than one DataReader at a time, which happened quite often, you would find multiple components on the same form.  These components were never renamed from the defaults, hence the numeric numbering scheme.

    The connection number is not an index into an array, nor a reference to a global variable.  It is the number of the component embedded as a member variable of the calling form!

  • Chris F (unregistered) in reply to Chris F

    The above reply was in reference to a post about turning on Option Strict.  Sorry for the lack of a quote.

  • Chris F (unregistered) in reply to Alex Papadimoulis
    Alex Papadimoulis:
    Sadly .. it actually is VB.NET ... I have another example from this project I'll be posting sometime later. One tell-tale sign is the use of the Return keyword. VB6 does not support it.

    The other beautiful tidbit I sent is actually from a classic ASP project, although I'd swear the authors are related somehow.  This example is indeed VB.Net.  I could feed this site for some time with examples from the two of these. =)
  • Paul (unregistered) in reply to Chris F

    I think this code would be great in a job interview...

    Hand the code to a prospective applicant and if their eyes don't roll into the back of their head, end the interview

  • (cs) in reply to Jon Limjap

    Jon Limjap:
    christoofar:
    OMG nevermind, this is VB.NET code.... oy vey brand new language, and now brand new WTFs to be generated every day.


    It's not VB.NET, mind you. It's Visual Basic 6.

     

    It is VB.Net actually, OrElse, as stated above, the 'return' keyword does not work.
    The Exit Function also seems to be a blast from the past. I was handed a bit of VB6 code, and it consists mostly of:

    On Error GoTo ErrorHandler
    ....
    ....
    FunctionEnd:
    Exit Function
    ErrorHandler:
    ....
    Resume FunctionEnd

    So I'm guessing that this had one of those constructs before, it didn't work, they took it out and forgot the Exit Function.

     

    Drak

  • (cs) in reply to Drak

    OK, this is OT, and a dumb question, but... how do you quote previous messages in this forum software?  I can't see any button or other option to do it.  I'm assuming it's broken, whatever it is, or every second quote wouldn't be a mess of HTML, but it's all too uniform for it to be hand-coded, and anyhow I can't see an emoticon for the "speech bubble" icon, so... how does it work?  Someone enlighten me!

    And while we're at it: Alex, why are there so many options in the toolbar that don't work - clear formatting, the apparent Office-like dropdown icons, the on-again/off-again HTML editing mode, and so on?  Why not just remove them until you get a chance to fix them?

  • BPFH (unregistered) in reply to Anonymous
    Anonymous:

    short:
    Sean:
    I swear I worked with a guy that wrote code like this.

    i'm still working with one of those :)

    Mike R, rotfl :D

    Who knows maybe you two are colleagues!

    As long as they don't mean each other ... *lol*

  • (cs) in reply to bat
    bat:
    OK, this is OT, and a dumb question, but... how do you quote previous messages in this forum software?  I can't see any button or other option to do it.  I'm assuming it's broken, whatever it is, or every second quote wouldn't be a mess of HTML, but it's all too uniform for it to be hand-coded, and anyhow I can't see an emoticon for the "speech bubble" icon, so... how does it work?  Someone enlighten me!

    And while we're at it: Alex, why are there so many options in the toolbar that don't work - clear formatting, the apparent Office-like dropdown icons, the on-again/off-again HTML editing mode, and so on?  Why not just remove them until you get a chance to fix them?


    To quote a message, one clicks the 'quote' button available on all posts.

    Alternatively, use the board-code with (quote) and (/ quote)
    Replace () with [], mind you.
  • (cs) in reply to dhromed

    *let me rephrase elegantly, since this is a coding forum:

    var codeQuotes = '(quote)(/quote)';

    codeQuotes = codeQuotes.replace(/(/g,'[');
    codeQuotes = codeQuotes.replace(/)/g,']');

  • (cs)

    It's obviously code from some twisted, evil alternate dimension.  I mean, no one capable of compiling any piece of code could actually believe that that's gonna work.  Right?  Right?  Please tell me I'm right...?!

  • Welcome To The Machine (unregistered) in reply to Drak
    Drak:

    The Exit Function also seems to be a blast from the past. I was handed a bit of VB6 code, and it consists mostly of:

    On Error GoTo ErrorHandler
    ....
    ....
    FunctionEnd:
    Exit Function
    ErrorHandler:
    ....
    Resume FunctionEnd

    So I'm guessing that this had one of those constructs before, it didn't work, they took it out and forgot the Exit Function.

     

    Drak

     

    This is how any error handling in VB6 has to be done unless you want to do:

    On Error Resume Next
       result = CallSomeFunction()
       If err.number <> 0 Then
          'error handling in here
       End If

    By putting it at the end you can then have a catchall and, after the FunctionEnd label, destroy any objects you need to, close any connections etc.

    Of course, I've seen someone write something that screwed up in the bit after the FunctionEnd label and it did something like this:

    On Error GoTo ErrorHandler
    ....
    ....
    FunctionEnd:
    SqlConnection.close()
    Exit Function
    ErrorHandler:
    some function call to write an error file (with a guid-based unique name) to the folder this dll is in
    Resume FunctionEnd

    Of course, the problem was that the sqlconnection object was not open, so the .close() method failed, so it went round in circles writing a little text file to the folder the dll was in.

    It didn't work last thing on the Friday so they left it until Monday morning. By Monday the hard drive of the server was full of little text files and errors were pouring out of the machine for unrelated reasons. Until we tracked down the problem we thought there must be some kind of file system error in that folder as we couldn't browse to it in Windows (cos it had 30,000,000 text files in it).

    Eventually killed the process and went into a command prompt in the relevant folder and typed "del *.txt". It took 4 hours to delete them.

    Always very important to have proper error handling in your error handling ;-)

  • (cs) in reply to rogthefrog
    rogthefrog:
    In the car this morning I was wondering if VB had singlehandedly provided the world with the biggest number of WTFs, both in absolute terms and relatively to, say, the installed code base. This site seems to confirm my fear.

    A friend of mine once said: "Languages without semicolons just don't work". [:D]

  • (cs)
    Alex Papadimoulis:
    Worse still, it's only the tip of the iceberg ...
    Let us know which educational institute that developer coder came from, so we'll never send our kids there.
  • (cs) in reply to Jon Limjap

    Tell me, where in VB6 do you use the Return keyword?

  • (cs) in reply to icelava
    icelava:
    Let us know which educational institute that developer coder came from, so we'll never send our kids there.

    You are too kind: "Let us know which educational institute that developer coder typist came from, so we'll never send our kids there."

    He or she probably "picked it up" at his last job.  (Which I assume was not long ago and, I expect, it will not be long until his next job.)


  • (cs) in reply to triso
    triso:
    icelava:
    Let us know which educational institute that developer coder came from, so we'll never send our kids there.

    You are too kind: "Let us know which educational institute that developer coder typist came from, so we'll never send our kids there."

    He or she probably "picked it up" at his last job.  (Which I assume was not long ago and, I expect, it will not be long until his next job.)




    Who hires a guy like this anyway?  A manager dumb enough to keep him on board probably goes for the gusto and puts him on some important system, like payment processing.
  • mysticwhiskey (unregistered) in reply to Jon Limjap

    Nah, don't think so, as the 'return' keyword is not present in VB 6.

  • Justin Sippel (unregistered)

    Wow.

    Wow.

  • (cs)

    Let me also add that I find it amazing that a function called "CloseConnection" doesn't even do what it says, close a connection.  This alone is a WTF in my book, the function should be called "IsConnectionClosed" or what not.


    If I was reading over his code and I saw something like
    <FONT face="Courier New">If (NOT CloseConnection(myConnection))
    {
        myConnection.Query mySql;
        //etc
    }</FONT>

    I would be like "what the hell is he doing, he just closed the connection!

  • (cs) in reply to travisowens
    travisowens:

    Let me also add that I find it amazing that a function called "CloseConnection" doesn't even do what it says, close a connection.  This alone is a WTF in my book, the function should be called "IsConnectionClosed" or what not.

    I doesn't do much of anything but I think the intention was to close the connection, I mean I would think Close() would close the connection.  Otherwise it's exactly the kind of WTF you are describing.

  • Anonymous (unregistered) in reply to bat
    bat:
    how do you quote previous messages in this forum software?

    I think the real question is.... How do you quote without having all the HTML show up???

  • (cs) in reply to bat
    bat:
    OK, this is OT, and a dumb question, but... how do you quote previous messages in this forum software?

    On my screen, every post has three buttons: Reply, Quote, and Troll.
    You must click on Quote to get the quote.

    Or, if you know BBcode you can just type it in directly into the post.  It looks like this:
    (quote user="bat")OK, this is OT...(/quote)
    using square brackets instead of curve brackets.

    The forum software works best in Internet Explorer, it is acceptable in Firefox, and other browsers may vary.  The broken posts are coming from people using "other" browsers.  The worst part is that your post might look fine in the preview screen, but get mangled on the public view.

  • Ryan Anderson (unregistered) in reply to John Bigboote
    John Bigboote:
    Most languages just give you enough rope to hang yourself.

    VB without Option Strict allows you to implicitly convert everyday household objects into EVEN MORE rope.


    I thought the philosophy of Unix was to give admins enough rope to shoot themselves.

  • (cs) in reply to Anonymous
    Anonymous:

    short:
    Sean:
    I swear I worked with a guy that wrote code like this.

    i'm still working with one of those :)

    Mike R, rotfl :D

    Who knows maybe you two are colleagues!



    Or they are talking about each other.  ;)
  • (cs) in reply to icelava
    icelava:
    Alex Papadimoulis:
    Worse still, it's only the tip of the iceberg ...
    Let us know which educational institute that developer coder came from, so we'll never send our kids there.


    That guy isn't a coder.  He's a Certified Voodo Coder.  He gets his job done by typing in a bunch of arcane looking symbols, praying to the Dark God of Databases and sacrificing a chicken.   If it still doesn't work,  break out the chicken crate and some towels because things are gonna get bloody.
  • (cs) in reply to loneprogrammer
    loneprogrammer:
    bat:
    OK, this is OT, and a dumb question, but... how do you quote previous messages in this forum software?

    On my screen, every post has three buttons: Reply, Quote, and Troll.
    You must click on Quote to get the quote.

    Or, if you know BBcode you can just type it in directly into the post.  It looks like this:
    (quote user="bat")OK, this is OT...(/quote)
    using square brackets instead of curve brackets.

    The forum software works best in Internet Explorer, it is acceptable in Firefox, and other browsers may vary.  The broken posts are coming from people using "other" browsers.  The worst part is that your post might look fine in the preview screen, but get mangled on the public view.



    On firefox I can quote nicely. I think it's a multi-step process:

    1) Find the finest live chicked you can.
    2) Offer the chicken as a sacrifice to the gods of unmangled forum posts
    3) Cross your fingers and say the secret chant 3 times.
    4) Click the "Quote" button.

    I suspect some people on this forum are not following the proper quoting procedure, which is why you see a lot of raw HTML.
  • (cs)

    This code is so retarded that it took me 5 minutes of head-scratching to finally realize that "OMG THIS CODE IS RETARDED!".  I think this might be a proverbial "stupid singularity" that opens "stupid anomalies" that suck the intelligence out of the universe.  I fear that I may have to dust off my bogon interferometer and cluon generator and purge myself of this... travesty.

    All ludicrosity aside, maybe this was an OCaml programmer who was used to assigning function names as strings in the hope that they would be executed recusively.

  • (cs) in reply to Mike R
    Mike R:
    I suspect some people on this forum are not following the proper quoting procedure, which is why you see a lot of raw HTML.

    No.  I have followed the same procedure using Firefox 1.0 and Mozilla 1.0, and the raw HTML resulted from using the older browser.  And it looked right in the preview screen!

  • (cs) in reply to Jon Limjap

    Jon Limjap:
    christoofar:
    OMG nevermind, this is VB.NET code.... oy vey brand new language, and now brand new WTFs to be generated every day.


    It's not VB.NET, mind you. It's Visual Basic 6.

    No, it isnt.  VB.NET is the ONLY VB with Return.

  • PJ (unregistered) in reply to Otac0n

    I think I remember now why I never wanted to take the college's VB class after having experienced it in high school. I'm sorry VB programmers but that syntax is horrible.

  • (cs) in reply to PJ

    Anonymous:
    I think I remember now why I never wanted to take the college's VB class after having experienced it in high school. I'm sorry VB programmers but that syntax is horrible.

    uh ... what syntax?

  • simon (unregistered) in reply to Jeff S
    Jeff S:
    Anonymous:
    I think I remember now why I never wanted to take the college's VB class after having experienced it in high school. I'm sorry VB programmers but that syntax is horrible.
    uh ... what syntax?

    Hell if I know. I thought VB had some sort of IDE with one control, an 'insert WTF here'

    Simon

  • (cs) in reply to Mike R

    Mike R:

    I suspect some people on this forum are not following the proper quoting procedure, which is why you see a lot of raw HTML.

    Not true, it's all about the user-agent [:P]

    In IE, I can quote perfectly, but using Opera lots of raw HTML shows up for some reason.

  • (cs)

    Be very careful looking at this code, trying to determine whether the person who wrote it was an evil genius or an idiot.  I am not certain it is either.  A subspace Vacuole opened up on my monitor while starring at it.  A pissed off Klingon came out wearing a "VB rules" tee shirt and chased off our one and only female programmer we have ever worked with or known in this dimension.

    She programs in VB but uses Option Explicit.  Oh no, he has a bat'Leth!

    You know you have seen really bad code when this happens.  Where is our chief science officer?

    C# rules....

     

  • John V (unregistered)

    VB is even stranger than I was aware of.  I did some testing (in VB6) and it looks like this code might work if, similar to what RayS suggested, perhaps the line were re-written as

    ReturnStatus = Excecute("sqlConnection" & CStr(connectionNum) & ".Close()")

    Then ReturnStatus could hold an integer after that line which indicated whether or not the Close was successful.

    The other apparent problem is Returning True/False when the return type is set to Integer.  In VB, you can say variable = False (where variable is dim'd as Integer) and it will set the variable equal to zero (-1 for True, WTF?), so that would work, although it does seem like it would make much more sense to just make the return time boolean.

    However, the problem then would be if the Execute() command failed, which would leave the ReturnStatus int as it's initialized value of zero, and thus the function would return "True", when I'd imagine you'd want it to return False (indicating the close was unsuccessful).

  • (cs) in reply to John V
    Anonymous:
    In VB, you can say variable = False (where variable is dim'd as Integer) and it will set the variable equal to zero (-1 for True, WTF?),

    Using -1 for true isn't that WTFish, IMHO.  In a system using twos-complement (i.e. everything), -1 is represented in binary as all 1s, and using the "all 1s" value isn't an unreasonable extension of the boolean algebra convention of using 1 for true and 0 for false, particularly when you consider that it means that logical and bitwise operations (AND, OR, NOT, etc.) are the same.  It's not what C and all its babies do, but it's not really a WTF.
  • (cs) in reply to AJR
    AJR:
    Anonymous:
    In VB, you can say variable = False (where variable is dim'd as Integer) and it will set the variable equal to zero (-1 for True, WTF?),

    Using -1 for true isn't that WTFish, IMHO.  In a system using twos-complement (i.e. everything), -1 is represented in binary as all 1s, and using the "all 1s" value isn't an unreasonable extension of the boolean algebra convention of using 1 for true and 0 for false, particularly when you consider that it means that logical and bitwise operations (AND, OR, NOT, etc.) are the same.  It's not what C and all its babies do, but it's not really a WTF.


    -1 for true isn't that bad in itself, but it's a symptom of an inexcusable design flaw.  As you put it, AND, OR and NOT are both bitwise and logical; really, they're only bitwise.  Using -1 for true allows the standard operations to work when you stick to strictly boolean expressions, but strange things happen with shortcuts.  For instance, If InStr("1234", "1") Then MsgBox "True" will show True, and If InStr("1234", "2") Then MsgBox "True" will show True; however, If InStr("1234", "1") And InStr("1234", "2") Then MsgBox "True" will not..

    I understand why you would do this trying to fit a BASIC interpreter in the 8K ROM of the Altair, but there's no excuse for this not being fixed in MS BASIC well before 1980.
  • (cs) in reply to Otac0n
    Otac0n:

    Jon Limjap:
    christoofar:
    OMG nevermind, this is VB.NET code.... oy vey brand new language, and now brand new WTFs to be generated every day.


    It's not VB.NET, mind you. It's Visual Basic 6.

    No, it isnt.  VB.NET is the ONLY VB with Return.

     

    NGGGGGGG! No it is not. VB6 has the Return keyword. Except that it expects only to be called after GoSub. Which is perfectly normal behaviour in BASIC since VIC 20 basic or even earlier.

    Drak

  • (cs) in reply to loneprogrammer
    loneprogrammer:
    Mike R:
    I suspect some people on this forum are not following the proper quoting procedure, which is why you see a lot of raw HTML.

    No.  I have followed the same procedure using Firefox 1.0 and Mozilla 1.0, and the raw HTML resulted from using the older browser.  And it looked right in the preview screen!


    Are you sure? Did you use a quality chicken?
  • (cs) in reply to PstScrpt

    PstScrpt:
    If InStr("1234", "1") Then MsgBox "True" will show True, and If InStr("1234", "2") Then MsgBox "True" will show True; however, If InStr("1234", "1") And InStr("1234", "2") Then MsgBox "True" will not..

    And If InStr("1234", "1") And InStr("1234", "3") Then MsgBox "True" will, right?  Since InStr returns the position of the "found" string (1-based)

  • (cs) in reply to Maurits
    Maurits:

    PstScrpt:
    If InStr("1234", "1") Then MsgBox "True" will show True, and If InStr("1234", "2") Then MsgBox "True" will show True; however, If InStr("1234", "1") And InStr("1234", "2") Then MsgBox "True" will not..

    And If InStr("1234", "1") And InStr("1234", "3") Then MsgBox "True" will, right?  Since InStr returns the position of the "found" string (1-based)


    This is why CBool exists. I think VB goes through some logical contortions to make things like this work, but maybe not. Give it a shot.

    Didn't we have this VB Operators discussion last week?

    AJR:
    Using -1 for true isn't that WTFish, IMHO.  In a system using twos-complement (i.e. everything), -1 is represented in binary as all 1s, and using the "all 1s" value isn't an unreasonable extension of the boolean algebra convention of using 1 for true and 0 for false, particularly when you consider that it means that logical and bitwise operations (AND, OR, NOT, etc.) are the same.  It's not what C and all its babies do, but it's not really a WTF.

    You mean, I'm sure, that's EXACTLY how C and all its babies do. Okay, Java gets nitpicky, but the vast majority of the C standard libary returns 1 or -1 on success, 0 on failure, and if you ever cast a logical comparison to an integer and output it, it'll be -1 or 0. (or 2^(8*x)-1)

    Of course, the wtf of a few random functions reversing the success/failure values shall go unranted, for now.
  • (cs) in reply to Mike R
    Mike R:
    loneprogrammer:
    Mike R:
    I suspect some people on this forum are not following the proper quoting procedure, which is why you see a lot of raw HTML.

    No.  I have followed the same procedure using Firefox 1.0 and Mozilla 1.0, and the raw HTML resulted from using the older browser.  And it looked right in the preview screen!


    Are you sure? Did you use a quality chicken?


    Frozen fowl will not do for voodo ceremonies.  I know, we have them all the time where I work.
  • (cs) in reply to tiro
    tiro:

    Frozen fowl will not do for voodo ceremonies.  I know, we have them all the time where I work.


    Absolutely. It must be live.

    And besides -- If you've ever heard the Sanderson Farms Chicken commercials (Mother Nature .. blah) then you know frozen chickens are pumped up with salt and phosphates. Do you have any idea what that could do to a voodoo ceremony?
  • (cs) in reply to Mike R
    Mike R:
    tiro:

    Frozen fowl will not do for voodo ceremonies.  I know, we have them all the time where I work.


    Absolutely. It must be live.

    And besides -- If you've ever heard the Sanderson Farms Chicken commercials (Mother Nature .. blah) then you know frozen chickens are pumped up with salt and phosphates. Do you have any idea what that could do to a voodoo ceremony?


    Um, create an undead zombie chicken, who's immune to +1 weapons and lower?
  • (cs) in reply to Mike R
    Mike R:
    And besides -- If you've ever heard the Sanderson Farms Chicken commercials (Mother Nature .. blah) then you know frozen chickens are pumped up with salt and phosphates. Do you have any idea what that could do to a voodoo ceremony?
    I guess using a microwave oven to heat things up is out of the question then.....
  • OneFactor (unregistered) in reply to Charles Nadolski

    Charles Nadolski:
    Mike R:
    tiro:

    Frozen fowl will not do for voodo ceremonies.  I know, we have them all the time where I work.


    Absolutely. It must be live.

    And besides -- If you've ever heard the Sanderson Farms Chicken commercials (Mother Nature .. blah) then you know frozen chickens are pumped up with salt and phosphates. Do you have any idea what that could do to a voodoo ceremony?


    Um, create an undead zombie chicken, who's immune to +1 weapons and lower?

    Zombies are not immune to +1 weapons and lower, they just attack last on any given combat round. If you want something immune to non-magical weapons, you need at least a Wight.

    To create a Wight, you need validation fields that reject First names with fewer than 5 characters. This will tempt users like Luke, Alex, Nika, and Carl to pad their names with WightSpace in order to pass validation. If these users then try to sacrifice a chicken in order to get their quotes to show up they must use a live chicken OrElse the WightSpace will imbue the frozen chicken with  the unlife associated with code that depends on the absence of short-circuit boolean logic.

    These monstrosities cannot be improved without the aid of magic, but they do dress very well and charge $500K for software infected with unlife.

  • (cs) in reply to OneFactor
    Re "This is how you do error handling in VB".  No, it's not.  I program in VB6 sometimes, and here's how I do it for programs used by our internal departments:
     
    On Error Goto FileOpenError
    ... try to open a file here...
     
    On Error Goto 0
    ... code that shouldn't fail and hasn't failed in years goes here...
    [Goto 0 means stop the program with the error message visible]
     
    On Error Goto ErrorTrap
    ... code that generally won't fail but you might want a nice user-friendly error message if something goes wrong goes here...
     
    I never use On Error Resume Next; On Error Goto 0 is better in the sense that you'll at least know that something failed. 
     
    Those things like FileOpenError are labels that appear later in the program, and they usually pop up a message box, send an e-mail to the programmer, or whatever other action you want to program.
     
    And VB (version 6 and earlier) makes it easy for people to Get Things Done, and sometimes they are not professional programmers.  Some of them take the time to learn real programming eventually, even if it's in VB, and some of them keep writing bad code.  There's a bunch of good VB code out there, and there's a bunch of bad VB code out there, and I'm sure we'll all be amused forever by examples of horribly bad VB code.  I'm sure amused by the examples on this site!
     
    Now I use VB.NET instead of VB6 when I can, but sometimes, I'm writing programs that run in Excel... some of them are bigger than what you commonly call "macros".
     
    I don't want to start a language war, which of course no one can win, but please, people, realize that the existence of horrible VB code in the world doesn't mean that VB itself has no place, and it doesn't mean that there's no good, useful, well-written VB code in existence.
     
    David Walker
  • (cs) in reply to DWalker59
    For the people who commented "How could this possibly compile", um, VB is not a compiled language. The IDE generally tells you when you do something bad, but the programs are not "compiled" in the traditional sense.  When you try to run a program, mismatched or unclosed If/Then/Else statements will give you a warning, though.
     
    Return is used with Gosub, which is left over from WAY old versions of VB.  So there IS a Return statement.
  • (cs) in reply to DWalker59
    DWalker59:
    For the people who commented "How could this possibly compile", um, VB is not a compiled language. The IDE generally tells you when you do something bad, but the programs are not "compiled" in the traditional sense.  When you try to run a program, mismatched or unclosed If/Then/Else statements will give you a warning, though.

     

    This isn't true, at all.

Leave a comment on “Drowning in the Connection Pool”

Log In or post as a guest

Replying to comment #:

« Return to Article