• (cs) in reply to TechNoFear

    TechNoFear:
    how does it do this ?

    Precedence operators.  What's in the parentheses is calculated first, and then a is set equal to the result.

    VB classic used variant variable types extensively.  They could become any type simply by assignment.  If you didn't explicitly declare your variable (and if you didn't use "Option Explicit" to require explicit variable declaration), then upon the first use of an undeclared variable it was created as a variant.  In the example above, if a hasn't been declared somewhere above, it begins as a variant and then becomes a boolean by assignment.

     

  • zamies (unregistered) in reply to oliver

    Well I wouldnot hire you :)

    The code could be shortened by a factor 20.

    And the code is incorrect :)

    'the month is february, check for leap year
           Case 2 :
                remainder = yearNumber Mod 4
    is incorrect!

     

  • asdfasdf (unregistered) in reply to Ben
    Anonymous:

    P.S. This happens everytime you first submit a post as an anonymous user:

    <font color="#ff0000">Something didn't quite work out ...
    - CAPTCHA Validation Incorrect</font>


    Blocked cookies will cause this.

  • blah (unregistered) in reply to Dave
    Anonymous:
    bit:
    I especially like the manually incremented FOR loop.

    I'm not sure I see the problem with the manual increment (beyond the poor documentation):  the code intends to only check positions 3 and 6 (2 and 5?? Where's my reference guide? anyway, the separator positions) within the string.  Sure, the author could have simply extracted mid(,3,) and (,6,) and duplicated the if statement, but either approach can be successful.

    What I worry about is seeing an assignment, rather than a comparison, in the if statement ...
       if Not ( seperator = "/" Or separator = "-" Or separator = "."  ) ...


    I believe that the equal sign is also a comparison operator in VB....
  • Igor Tchernov (unregistered)

    But I belive you've got most adequate what you have requested - if you smart enought to ask such a question for $250/h you should expect such an answer. And the consultant seems to have a good sense of humour.

  • hognoxious (unregistered) in reply to Anonymous
    Anonymous:
    The real WTF here is that the month and day are switched.
    Let me guess - you don't have a passport, right?
  • Paulo Piccasso (unregistered) in reply to Mika

    Correct me if I am wrong but would this even build as you are supposed to be returning an integer yet you return a boolean??

  • Silly_Brit (unregistered)

    it is awful because it was done by someone who didn't realize that an IsDate function exists.

    Obviously a lot of people have never tried validating dates with IsDate() in VB6 IsDate("1") returns true!! Isdate("1 1") returns true!! Don't even think about handling different locales with it either! I've always found it easier to validate the date myself in VB (pre .net).

  • (cs) in reply to Anonymous
    Anonymous:

    That was supposed to be:

    Anonymous:
    The real WTF here is that the month and day are switched.

    Only in America.



    I thought it was funnier the first time...
  • (cs) in reply to Maurits
    Maurits:
    Oops, == has higher precedence than both && and ||
    Fixed versions:

        // optimized for readability
        return
            (year % 400 == 0) || // 2000, 2400, etc. are leap years
                (year % 4 == 0) && // most other divisible-by-4 are leap years
                (year % 100 != 0) // except for 2100, 2200, 2300, 2500...
        ;

        // optimized for speed
        return
            !( // faster to check for non-leap years
                (year % 4) != 0) || // 75% of the time this short-circuits
                (year % 100 == 0) && // 75% of the time this short-circuits
                (year % 400 != 0)
            );


    Surely if == has higher precedence than || and && you were right the first time?
  • Andy O. (unregistered) in reply to XYZ
    Anonymous:
    Unfortunately this doesn't take account of the fact that years divisible exactly by 100 aren't leap years unless they are also divisible exactly by 400.


    Yep, that's what I thought, too!


  • meow (unregistered) in reply to boohiss

    doesn't the game exist, only because there are players??? fo shizzle

Leave a comment on “Your $2000 Function, Rebilled”

Log In or post as a guest

Replying to comment #:

« Return to Article