ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

What was I thinking last weekend ?

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

  • What was I thinking last weekend ?

    Last week I was coding a dateselection progam. (between 2 dates)

    The database used a 8 numeric field in the form of YYYYMMDD.
    The Disply had 3 numeric fields with EDTCDE(4)

    C1day 2,0
    C1month 2,0
    C1year 4,0


    The user could make the fields "looks" blank because I used EDTCDE(4). ( I don't want to show them zero !! )
    That was ok, but what if he did: __ __ 2008 ? The setll and a READP ! on the db works ! 20080000

    But the user may expect the result from the year 2008 to !
    So, to attend them, I code the zero's so would see _1 _1 2008 instead !

    But now I have coded something like this:

    If C1day = *zero
    Eval C1day = 1
    Endif

    If C1month = *zero
    Eval C1month = 1
    Endif

    and because I have 2 selectiondates

    If C2day = *zero
    Eval C2day = 1
    Endif

    If C2month = *zero
    Eval C2month = 1
    Endif


    I don't like that kind of code, so I was thinking,
    could I program the "IF/../Endif" on 1 line ?

    Then my idea hit me, I rememberd that: cos(0) = 1 !
    so, instead if using the 3 line IF/../Endifthen I could code:

    eval C1day = cos(C1day)

    (W)That was I thinking last weekend ? !

    But than I remembered the wise words of my teacher !

    DON'T BE SMART !

    But the cos(x) works ! Read: High-Level Match Functions for RPG

    How would you have done it ?

  • #2
    Re: What was I thinking last weekend ?

    I would make them key in a valid date. I wouldn't give them the option of typing 00. I would make them at least select the first day of the first month if they want the whole year. We make our dates an 8 0 field usually MMDDYYYY. Then its easy to go from *USA to *ISO if need be for displaying purposes... Our records in our files are all in YYYYMMDD. Which is ok, its not idea, but its ok. But when I'm displaying dates I like to use the actual date type because it prints all the dashes or slashes I need.

    You just need to validate up front and make sure the date is valid before processing. Allowing users to get away with entering garbage will only encourage bad habits. Garbage in is garbage out.

    $.02 on a Monday before caffeine.
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

    Comment


    • #3
      Re: What was I thinking last weekend ?

      Why not provide a "default" date with the Current Year? 01 01 2008? Or, if there's a specific range they use continually... default to that. It removes the issues you mention and provides you with valid information.

      jmho

      -R

      Comment


      • #4
        Re: What was I thinking last weekend ?

        What you all say is right !

        "You just need to validate up front and make sure the date is valid before processing.
        Allowing users to get away with entering garbage will only encourage bad habits. Garbage in is garbage out."


        Just a note: I don't use the dates for updating the database.

        The program I was working on just showed what product (on a date) was made between 2 dateranges.

        With a Key (product, dbdate(YYYYMMD)) and setll and readp
        I could leave the second date on *zero and it worked ! ( = select all from first date)

        The problem I encountered was, a user filled a part of the start date
        ( user usual enters the year only ) the user expected that the generated list included the production for that year.

        The reason why I use this "partial date" technique is, that a user
        only have to enter the datefield they want, let me explain:


        If on the screen I had the 3 part date (DD MM YYYY): __ 10 2007
        the user could easely change the month or the year without
        typing the whole date like: 01122008

        Even if the user typed something like 39 33 2008 the user would select the whole year because I used Settll readp !
        (It didn't matter, It allways works and I had no need to to check for errors !)

        But , I agree with you, what you say is right !

        I should used real dates ! (even for this kind of simple date selections )

        I started rewriting my dateselection program!

        The user is no more KING !

        Comment


        • #5
          Re: What was I thinking last weekend ?

          See, 39 33 2008 should either do one of two things... it should actually start at 09 10 2010 <- this is the date if you add these months and days on top of the year, or it should cause an error on the screen because 39 and 33 are not valid selections. If you make them enter valid selections then they won't be confused about the results that they expect in return... garbage in/garbage out isn't just about database updating. It applies to everything you do with the data, even querying.
          Your future President
          Bryce

          ---------------------------------------------
          http://www.bravobryce.com

          Comment

          Working...
          X