- 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
No. Freakin'. Way.
Admin
my god... would the non-zero values actually be preserved in that case, (e.g. does the boolean actually store a short integer) or does it get converted into True?
Admin
implicitly the 2 and the 1 both get converted to "True", I believe.
I LOVE option explicit -- it is the best thing to hit VB since sliced bread.
I'd be curious to see how many VB.NET developers use it ... it still frightens me that so many poeople don't even use Option Explicit !! (in both .NET and regular VB6 and even VBScript)
Admin
I don't know why you non-VBers like to mock VB programmers so much. Just deal with your jealousy. Our booleans go up to 2 and our amplifiers go up to 11. Sure, I know what you're thinking, "if he used SELECT CASE he could go even higher..." That's where you're WRONG bucko! Nested If..Then statements are the only way to take our ultimate programming powers to the next level - boolean = 3!!
Admin
oops -- I meant "Option Strict" in the first instance... sorry for the confusion.
(i really wish we could have a 5 minute window to edit posts!!)
Admin
What is the return value if the user is not in Admin, Training, or Supervisor?
Admin
And of course there's the Win32 call TrackPopupMenu:
"If you specify TPM_RETURNCMD in the uFlags parameter, the return value is the menu-item identifier of the item that the user selected. If the user cancels the menu without making a selection, or if an error occurs, then the return value is zero.If you do not specify TPM_RETURNCMD in the uFlags parameter, the return value is nonzero if the function succeeds and zero if it fails. To get extended error information, call GetLastError."<mshelp:link tabindex="0" keywords="_win32_GetLastError" xmlns:mshelp="http://msdn.microsoft.com/mshelp"></mshelp:link>
Admin
Let me just say.... I am a C# developer who went into a VB.NET firm to consult and make recommendations...... I turned Option Explicit ON - and VS 2003 said there were "too many errors to display" ;) On 1 WINDOWS FORM.... NOT EVEN COUNTING THE OTHER 30+ forms. (Yes 30+ forms of repetative code...) No modules, and no user controls. ;)
needless to say... my recommendation was to REWRITE everything using ACTUAL .NET rather then VB6 with VB.NET functions and methods ;)
Chris
Admin
You'll just have to learn to be publicly humiliated and apologetic like the rest of us, Jeff. Isn't it incredible how many run-time mysteries become compile-time wavy underlines with circles and arrows and flashing lights and sound effects when you use Option Explicit/Option Strict?
Admin
<font style="BACKGROUND-COLOR: #efefef">OOPs i meant STRICT too! see what you did?? Damn VB.
-Chris
</font>
Admin
Well, you see, there's false, true, and REALLY true.
Admin
i bet all you C# guys out there are jealous of us VB guys with our Option Strict Off possibilities. Forget binary, man... with Option Strict Off, we can code in Trinary!
[:D]
the worst thing happening here is that when he doesn't return any value, it actually gets converted to "False" automatically... i hate that... if i return "Nothing" as a boolean, then I want it to be NOTHING, not False...
Admin
If you return "Nothing" as a Boolean, it's a String. That'll start a whole new thread.....
Admin
This is a stunning day in the history of computer science. A decompiler can actually generate better code than the original developer. Compile that fragment and Lutz Roeder's Reflector will generate this:
Admin
False, so a user without role has full rights (False = 0 = Admin)
Admin
Holy crap, you're right. Until you said that I didn't realize how WTF this code really was.
bj
Admin
The WTF here has got to be the word 'Friend'. I mean, do VB 'programmers' need to be mollycoddled that much?!
Next you'll tell me that static variables/methods are called something like Shared in VB, so you can share them with your Friends and all be happy!
Admin
VB's "Option Strict" is like perl's "use strict" - it should be on by default.
Admin
It isn't the VB team who invented friend -- it's a C++ oddity. Although my Computer Science background gets offended, I find the modifiers MustInherit, Overloads, Overrides, and NotOverridable much easier to read and see what's going on than the "semi-colon" eqivilants of abstract, <none>, <none>, and final ...
Admin
Actually all of you are missing the real culprit here. If only the CLR defined a Trilean data type, all would be just fine.
Geesh.
Bruce Johnson
http://www.objectsharp.com/blogs/bruce
Admin
I'll have to agree with you on this one. As much as I hate VB for its 'access for all' policy (anybody familiar with the new policy of English Universities will know EXACTLY what I'm talking about), C++ almost has an 'access for none' policy.
Although it's an undoubtedly very powerful and fast language, it is over-complicated, and those that use it revel in its ability to perform such wonderous feats as multiple-inheritance, among other miracles.
Java and C# are a wonderful halfway house, in that they are fairly simple to pick up, and code is actually human readable (unlike a lot of C++), but they are also not overly-simplified like VB so that there are less 'novices' (for want of a better word) using them to program things beyond their abilities, such as the guy who was using the WebClient class and clearly didn't have the first idea about HTML or HTTP (see one of my posts on a thread from a couple of days ago for the reference).
Admin
Boolean/bool is tristate anyway, surely? true, false and null
Admin
Anyone ever heard of the "quantum bool" (or something similar to that name)? It's some research project in which there can be a bool that's half on. Maybe he's just preparing for it? We could learn from him...
... The project does exist, but that rest is sarcasm if you haven't yet figured that out.
Admin
<font size="3">Hmmm.... Wouldn't this be easier, and fix the case of not belonging to a role causing the same result as an admin:
</font>
<font size="3">Yeah, I know, it's C# now, it would be easy to do in VB also.</font><font size="2">
</font></font><font size="2">
Admin
<font size="2">
Or the upcoming "bool?" in .NET 2.0 (nullable). That would be tri-state.
</font>
Admin
Reminds me of my favourite g++ warning:
(From http://groups-beta.google.com/group/rec.arts.int-fiction/browse_thread/thread/e59f834f272a596/d60167720a76102b - dear lord, the new Google Groups interface is bad. Google! What happened to you?)
Admin
Compilers have been able to generate "better" code than humans for ages now.
As far as booleans go, Microsoft has been pretty consistent in their implementations throughout their programming environments (databases or otherwise):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaoriDataTypesVBA.asp
"When numeric data types are converted to Boolean values, 0 becomes False and all other values become True. "
Maybe the programmer was just using 1 and 2 for his/her own reference within the scope of that function. Or it could be one of those temporarily invisible bugs just waiting to bite you one fine day.
Admin
It was on by default in the first Betas, but too many people complained that their code fell over. Unfortunately, Microsoft decided to change the default rather than sit those people down and explain patiently that if their code fell over it was a crock of s*** and they should stop calling themselves programmers.
I guess it goes to show there are some times when you shouldn't listen to the users.
Admin
Reminds me of a developer I used to work with who swore left and right that he'd come across a negative bit. That one still makes me chuckle.
Admin
Apparently you don't program in .NET. That is not the case.
Admin
ok, fair enough, then. true, false and unassigned. I make that a tristate!
Admin
I was under the impression that in VB.NET, if you do not return a value from a method, the compiler creates some MSIL which simply returns a variant - which is different from null. The C# compiler, however, does not allow for such nonsense.
Admin
<font size="2">"The C# compiler, however, does not allow for such "
In C# v2.0 there are nullable types, so you can write "bool?" and have true, false and null :)</font>
Admin
I was writing an interface layer for VBA once, and found an interesting bug. I was trying to make sure that I could set the value true and false, as well as query it to get correct values. My VBA for this was something along the lines of:
Boolean temp = iforget.getState()
print temp
temp = Not( temp )
iforget.setState( temp )
( I haven't touched VB since I coded the project, so that's probably not correct. But you get the idea.. )
Here's the intersting part. If the state was initially false, it'd be set to true. If the state was initially true, it'd be set to true.
In VBA, the bool value for true is 0xFFFF and the value for false is 0x0000. The Not function does a bitwise flip - so 0xFFFF <-> 0x0000. However, any non-zero value evaluates to true.
In C++, the bool value for true is 0x0001. And that's what I was returning to VBA. Unfortunately, the complement of 0x0001 is 0xFFFE, which also evaluates to true in VBA, and in C++. I fixed my code, but there were plenty of other places in the app where it wasn't fixed.
Admin
Admin
VB goes one step further, and doesn't even have methods. It has 'Functions' and 'Subs'. Surely that has to be another WTF! Either way, it's rubbish.
Admin
Hey David, ur solution suck & is a bigger WTF than the original post!
Admin
I've read through hundreds of lines of VB code before and have never seen a statement that begins with 'Dim'. Anyone know what that does?
Admin
Yes, it's a completely superfluous directive, of which there are many in VB ('as' and 'then' being just a couple more) which exist in VB and nowhere else which give VB 'programmers' a little helping hand because, let's face it, they need all the help they can get.
Admin
I .Net bool cant be null. So its still only 2 state :-)
Admin
But it can be unassigned. So that's a third state.
Admin
Admin
Try it for yourself:
bool x;
bool y = x; // compiler error: "Use of unassigned local variable x"
Admin
err spelling suck and err post is a bigger wtf than anything here.
Admin
The reason you don't see it is because everytime VB encounters it, it darkens the screen (hence the name Dim) . The strange thing is, option explicit seems to require it, which is why such a thing is not used.
(And in case anyone isn't aware this statement was completely toung-in-cheek)
Admin
<font style="BACKGROUND-COLOR: #efefef">How about:
True,
False, and
When I dream, I have a pony?</font>
Admin
<font style="BACKGROUND-COLOR: #efefef">It's a relic from GWBASIC where only arrays needed to be declared before using (hence, the DIMension statement). When QBasic came out, there were a few programs from MS to convert legacy GWBasic code. When VB came out, it was easy to bring QB logic. With VB.NET ... you get the idea.
no
I say, keep Dim as a synonym for the Declare. I think that'd be great .... Declare FirstName As String .... MS, go put it in the specs! Please [:^)]</font>
Admin
Admin
Admin