Announcement

Collapse
No announcement yet.

My first PB limitation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • My first PB limitation

    Expression too complex...

    IF (dwYear1 < dwYear2) OR _
    (dwYear1 = dwYear2 AND _
    (dwMonth1 < dwMonth2 OR _
    (dwMonth1 = dwMonth2 AND _
    ((dwLeapMonth1 = %TRUE AND dwLeapMonth2 = %FALSE) OR _
    (dwLeapMonth1 = dwLeapMonth2 AND _
    (dwDay1 < dwDay2 OR _
    (dwDay1 = dwDay2 AND _
    (dwLeapDay1 = %FALSE OR dwLeapDay2 = %TRUE)))))))) THEN



    I was trying to compare two dates on the Hindu lunar calendar to see if one was on or before the other.

    I guess I'll have to figure out a way to break it down into something with nested IF's..

    Rick
    ------------------------------------------------------------
    sigpic

    It has come to my attention that certain dubious forces are interpolating their desires in my search for Mom, apple pie and the girl you left behind. Stop it or I'll scream...

  • #2
    I found it (personally) too clumsey to combine AND _ and OR _ (underscores) in one expression. Makes for a really bad debug day.

    Try separating the AND _'s and OR _'s into separate expressons. If the AND _ winds up being true (or false) then check the OR _'s.
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment


    • #3
      Interesting, that was really the first "error 401" I saw ever with PB.
      Anyway, you can help yourself easily. Try this:

      Code:
       
      LOCAL dwYear1,dwYear2,dwMonth1,dwMonth2,dwLeapMonth1,dwLeapMonth2,dwDay1,dwDay2,dwLeapDay1,dwLeapDay2,e1,e2,e3,e4 AS LONG
       
      e1=(dwYear1 < dwYear2)
      e2=((dwLeapMonth1 = %TRUE) AND (dwLeapMonth2 = %FALSE))
      e3=(dwLeapDay1 = %FALSE) OR (dwLeapDay2 = %TRUE)
      e4=(dwDay1 = dwDay2 AND (e3))
       
      IF (e1) OR (dwYear1 = dwYear2 AND (dwMonth1 < dwMonth2 OR (dwMonth1 = dwMonth2 AND (e2 OR (dwLeapMonth1 = dwLeapMonth2 AND (dwDay1 < dwDay2 OR e4)))))) THEN
      --Theo Gottwald
      ------------------------------------------------
      76706 Dettenheim * Germany * [email protected]
      ------------------------------------------------
      Joses Forum * Theo's Link Site * IT-Berater.org

      Comment


      • #4
        Code:
        LOCAL ft1, ft2 AS FILETIME 
        LOCAL st1, st2 AS SYSTEMTIME
        
        st1 =  SYSTEMTIME representation of date_1  ' which is month, day and year 
        st2 =  SYSTEMTIME representation of date_2 
        
        SystemTimeToFileTime   st1, ft1 
        SystemTimeToFileTime   st2, ft2
        
        iCmp = CompareFiletime (ft1, ft2) 
        
        '==>  icmp here will tell you if date_1 greater, less or equal to date_2
        Bonus: you don't have to worry about leap years yourself.

        MCM
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Like you said, break it down.
          You might want to see which condition worked while testing
          Code:
          #COMPILE EXE
          #DIM ALL
          #INCLUDE "win32api.inc"
          FUNCTION PBMAIN AS LONG
            LOCAL result&,Yr1&,Mon1&,Day1&,Yr2&,Mon2&,Day2&
            result = Test(Yr1,Mon1,Day1,Yr2,Mon2,Day2)
            
          END FUNCTION
          FUNCTION Test(Yr1 AS LONG,Mon1 AS LONG,Day1 AS LONG, _
                        Yr2 AS LONG,Mon2 AS LONG,Day2 AS LONG) AS LONG
            LOCAL LMon1    AS LONG
            LOCAL LMon2    AS LONG
            LOCAL LDay1    AS LONG
            LOCAL LDay2    AS LONG
            
          IF (Yr1 < Yr2) THEN
            ? "Level 1. Year 1 is less than year 2"
          ELSEIF (Yr1 = Yr2)   AND (Mon1 < Mon2) THEN
            ? "Level 2. Year 1 equal year2 and Month 1 less Month 2"
          ELSEIF (Mon1=Mon2)   AND (LMon1 = %TRUE) AND (LMon2 = %FALSE) THEN
            ? "Level 3. Month 1 = Month2 and leap month 1 is true and leap month 2 is false"
          ELSEIF (LMon1=LMon2) AND (Day1 < Day2) THEN
            ? "Level 4. Leap month 1 = leap mnth2 and Day1 less Day2
          ELSEIF (Day1=Day2)   AND (LDay1= %FALSE) OR (LDay2 = %TRUE) THEN
            ? "Level 5. Day1 = Day2 and Leap day1 is false or Leap day2 = true"
          ELSE
            ? "Level 6. No condition meet"
          END IF
          END FUNCTION
          How long is an idea? Write it down.

          Comment


          • #6
            My First PB Limitation

            Thanks to all for your helpful feedback. I had already re-written the code segment before I checked back as:

            Code:
               SELECT CASE dwYear1
             
                CASE > dwYear2
             
                CASE ELSE
             
                    SELECT CASE dwMonth1
             
                    CASE > dwMonth2
             
                    CASE ELSE
             
                        IF (dwLeapMonth1 = %TRUE AND dwLeapMonth2 = %FALSE) OR _
                                (dwLeapMonth1 = dwLeapMonth2 AND _
                                    (dwDay1 < dwDay2 OR _
                                        (dwDay1 = dwDay2 AND _
                                            (dwLeapDay1 = %FALSE OR dwLeapDay2 = %TRUE)))) THEN
             
                            dwReturn = %TRUE
             
                        END IF
             
                    END SELECT
             
                END SELECT
            I couldn't use the example given for windows as the date was not a Gregorian but Hindu lunar date which involves leap months and days.

            Rick
            ------------------------------------------------------------
            sigpic

            It has come to my attention that certain dubious forces are interpolating their desires in my search for Mom, apple pie and the girl you left behind. Stop it or I'll scream...

            Comment

            Working...
            X