• (cs)

    No. Freakin'. Way.

  • (unregistered)

    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?


  • (cs)

    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)

  • (unregistered)

    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!! 

  • (cs) in reply to Jeff S

    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!!)

  • (unregistered)

    What is the return value if the user is not in Admin, Training, or Supervisor?

  • (unregistered)

    And of course there's the Win32 call TrackPopupMenu:

    BOOL TrackPopupMenu(
        HMENU hMenu,
        UINT uFlags,
        int x,
        int y,
        int nReserved,
        HWND hWnd,
        HWND prcRect
    );
    "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>


  • (unregistered)

    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

  • (cs) in reply to Jeff S

    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?

  • (unregistered) in reply to

    <font style="BACKGROUND-COLOR: #efefef">OOPs i meant STRICT too! see what you did??  Damn VB.

    -Chris
    </font>

  • (unregistered)

    Well, you see, there's false, true, and REALLY true.

  • (unregistered)

    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...

  • (cs) in reply to

    If you return "Nothing" as a Boolean, it's a String. That'll start a whole new thread.....

  • (cs)

    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:

    <font color="#1000a0">Friend</font> <font color="#1000a0">Function</font> get_CheckUserRole()<font color="#1000a0"> As </font>Boolean
    <font color="#1000a0">Dim</font> flag1<font color="#1000a0"> As </font>Boolean
    <font color="#1000a0">Dim</font> user1<font color="#1000a0"> As </font>SystemUser = SystemUser.CurrentUser
    <font color="#1000a0">If</font> user1.AssertRole(RoleTypes.Admin) <font color="#1000a0">Then</font>
    <font color="#1000a0">Return</font> <font color="#800000">False</font>
    <font color="#1000a0">End If</font>
    <font color="#1000a0">If</font> user1.AssertRole(RoleTypes.Training) <font color="#1000a0">Then</font>
    <font color="#1000a0">Return</font> <font color="#800000">True</font>
    <font color="#1000a0">End If</font>
    <font color="#1000a0">If</font> user1.AssertRole(RoleTypes.Supervisor) <font color="#1000a0">Then</font>
    <font color="#1000a0">Return</font> <font color="#800000">True</font>
    <font color="#1000a0">End If</font>
    <font color="#1000a0">Return</font> flag1
    <font color="#1000a0">End Function
    </font>
    Truly awe inspiring.

  • (unregistered) in reply to
    :
    What is the return value if the user is not in Admin, Training, or Supervisor?

    False, so a user without role has full rights (False = 0 = Admin)
  • (unregistered) in reply to

    Holy crap, you're right.  Until you said that I didn't realize how WTF this code really was.

    bj

  • (cs)
    Alex Papadimoulis:

    Without Option Strict Off, the compiler wouldn't even let you try to stuff three different return values into a boolean value, as Jeff Atwood's colleague likes to do ...

    Friend [snip.....]




    End Property


    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!
  • (unregistered)

    VB's "Option Strict" is like perl's "use strict" - it should be on by default.

  • (cs) in reply to DJDanny
    DJDanny:
    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!


    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 ...
  • (unregistered)

    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   

  • (cs) in reply to Alex Papadimoulis
    Alex Papadimoulis:


    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 ...


     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).
  • (cs) in reply to
    :
    Actually all of you are missing the real culprit here.  If only the CLR defined a Trilean data type, all would be just fine.


     


    Boolean/bool is tristate anyway, surely? true, false and null
  • (cs)

    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.

  • (cs)

    <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">[code language="c#"]
    </font><font size="3"><font face="Courier New">internal bool CheckUserRole
    {
     get
     {
      return ! SystemUser.CurrentUser.AssertRole(RoleTypes.Admin);
     }
    }
    </font>[/code]</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 size="2"> 

    </font>

  • (cs) in reply to Jacob K

    <font size="2">


    </font><font size="2">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...


    Or the upcoming "bool?" in .NET 2.0 (nullable).  That would be tri-state.

    </font>

  • (cs) in reply to DJDanny
    DJDanny:
    The WTF here has got to be the word 'Friend'. I mean, do VB 'programmers' need to be mollycoddled that much?!

    Reminds me of my favourite g++ warning:

    vmobj.h:1757: warning: `class CVmObjTable' only defines a private destructor and has no friends

    Poor, poor, suicidal class CVmObjTable. I wish I could give it a hug.

    (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?)

  • (cs) in reply to RJ
    RJ:
    This is a stunning day in the history of computer science.  A decompiler can actually generate better code than the original developer.


    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.
  • (unregistered) in reply to
    :
    VB's "Option Strict" is like perl's "use strict" - it should be on by default.


    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.
  • (unregistered)

    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.

  • (cs) in reply to DJDanny
    DJDanny:


    Boolean/bool is tristate anyway, surely? true, false and null


    Apparently you don't program in .NET. That is not the case.
  • (cs) in reply to mjwills
    mjwills:


    Apparently you don't program in .NET. That is not the case.


    ok, fair enough, then. true, false and unassigned. I make that a tristate!
  • (unregistered) in reply to mjwills
    mjwills:
    [image] DJDanny wrote:


    Boolean/bool is tristate anyway, surely? true, false and null


    Apparently you don't program in .NET. That is not the case.


    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.
  • (cs) in reply to

    <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>

  • (unregistered)

    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.

  • (cs) in reply to JoeNotCharles
    JoeNotCharles:
    [image] DJDanny wrote:
    The WTF here has got to be the word 'Friend'. I mean, do VB 'programmers' need to be mollycoddled that much?!


    Reminds me of my favourite g++ warning:


    vmobj.h:1757: warning: `class CVmObjTable' only defines a private destructor and has no friends

    Poor, poor, suicidal class CVmObjTable. I wish I could give it a hug.


    (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?)
  • (cs) in reply to
    :


    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.


    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.
  • (cs) in reply to David Crowell

    Hey David, ur solution suck & is a bigger WTF than the original post!

  • (cs)

    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?

  • (cs) in reply to Tom
    Tom:
    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?


    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.
  • (unregistered)

    I .Net bool cant be null.  So its still only 2 state :-)

  • (cs) in reply to
    :
    I .Net bool cant be null.  So its still only 2 state :-)


    But it can be unassigned. So that's a third state.
  • (cs) in reply to DJDanny
    DJDanny:
    [image]  wrote:
    I .Net bool cant be null.  So its still only 2 state :-)


    But it can be unassigned. So that's a third state.
  • (cs) in reply to alexb

    Try it for yourself:

    bool x;
    bool y = x; // compiler error: "Use of unassigned local variable x"

  • (cs) in reply to azz
    azz:
    Hey David, ur solution suck & is a bigger WTF than the original post!


    err spelling suck and err post is a bigger wtf than anything here.
  • (cs) in reply to Tom
    Tom:
    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?


    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)
  • (unregistered)

    <font style="BACKGROUND-COLOR: #efefef">How about:
    True,
    False, and
    When I dream, I have a pony?</font>

  • (unregistered) in reply to Tom

    <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>

  • (cs) in reply to DJDanny
    DJDanny:
    [image]  wrote:


    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.


    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.
  • (cs) in reply to DJDanny
    DJDanny:
    [image]  wrote:


    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.


    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.
  • (cs) in reply to DJDanny
    DJDanny:
    [image]  wrote:


    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.


    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.

Leave a comment on “Thank Goodness there's &quot;Option Strict Off&quot;”

Log In or post as a guest

Replying to comment #:

« Return to Article