- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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!).
Admin
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!
Admin
The above reply was in reference to a post about turning on Option Strict. Sorry for the lack of a quote.
Admin
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. =)
Admin
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
Admin
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
Admin
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?
Admin
As long as they don't mean each other ... *lol*
Admin
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.
Admin
*let me rephrase elegantly, since this is a coding forum:
var codeQuotes = '(quote)(/quote)';
codeQuotes = codeQuotes.replace(/(/g,'[');
codeQuotes = codeQuotes.replace(/)/g,']');
Admin
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...?!
Admin
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 ;-)
Admin
A friend of mine once said: "Languages without semicolons just don't work". [:D]
Admin
Admin
Tell me, where in VB6 do you use the Return keyword?
Admin
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.)
Admin
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.
Admin
Nah, don't think so, as the 'return' keyword is not present in VB 6.
Admin
Wow.
Wow.
Admin
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!
Admin
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.
Admin
I think the real question is.... How do you quote without having all the HTML show up???
Admin
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.
Admin
I thought the philosophy of Unix was to give admins enough rope to shoot themselves.
Admin
Or they are talking about each other. ;)
Admin
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.
Admin
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.
Admin
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.
Admin
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!
Admin
No, it isnt. VB.NET is the ONLY VB with Return.
Admin
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.
Admin
uh ... what syntax?
Admin
Hell if I know. I thought VB had some sort of IDE with one control, an 'insert WTF here'
Simon
Admin
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.
Admin
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....
Admin
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).
Admin
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.
Admin
-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.
Admin
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
Admin
Are you sure? Did you use a quality chicken?
Admin
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)
Admin
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?
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.
Admin
Frozen fowl will not do for voodo ceremonies. I know, we have them all the time where I work.
Admin
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?
Admin
Um, create an undead zombie chicken, who's immune to +1 weapons and lower?
Admin
Admin
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.
Admin
Admin
Admin
This isn't true, at all.