CONTACT US Phone: (412) 835-9417 Email: sales@vss3.com |
Tip #34 - Validate your Data
Programming does not have to leave everything up the the user. It should also not be so rigid that the functions must be reprogrammed each year to work correctly. Offer some flexibility but do not allow the user to make a critical mistake.
In any critical function that is date related verify the validity of the date.
(By critical function, I mean something that is intended to be done once, such
as posting, purging, archiving, printing checks or posting checks.)
If: | |
Then: | declare purge_date(8,mdy/,g) |
If: | |
Then: | input purge_date "Purge Date: (mm/dd/yy) > " |
If: | Purge_date gt (@td-"365") or getenv("PFCMARK") eq "" |
errorbox "Date must be before "<@td-"365"; EXIT |
Another way to control data is to supply the expected response when appropriate. For example, if a report is usually run for all transactions, but could be run for any date range. Offer the default choices and let the user change them for the less frequent report.
1 ------- - - - - - - - - - - - - - - - -
If: 'written by Nancy Palmquist
Then: 'use to select all items between two dates
2 ------- - - - - - - - - - - - - - - - -
If:
Then: declare testdate(8,mdy/)
3 ------- - - - - - - - - - - - - - - - -
If: fd ne ""
Then: goto pick
4 ------- - - - - - - - - - - - - - - - -
top If:
Then: input popup fd(10,mdyy/,g) "ENTER FROM DATE (mm/dd/yyyy) (\{\KZ:[ENTR]} for Earliest) >"
5 ------- - - - - - - - - - - - - - - - -
If: @sk="brky"
Then: exit; end
6 ------- - - - - - - - - - - - - - - - -
If: fd="" 'Oldest date system will understand
Then: testdate="01/01/"{getenv("PFCMARK"); Fd=testdate
7 ------- - - - - - - - - - - - - - - - -
If:
Then: input popup td(10,mdyy/,g) "ENTER TO DATE (mm/dd/yyyy) (\{\KZ:[ENTR} for Latest) >"
8 ------- - - - - - - - - - - - - - - - -
If: @sk="brky"
Then: exit; end
9 ------- - - - - - - - - - - - - - - - -
If: td eq ""
Then: testdate="12/31/"{mod(getenv("PFCMARK")+"99","100"); td=testdate
10 ------- - - - - - - - - - - - - - - - -
pick If: 3 lt fd or 3 gt td 'field 3 is a date field
Then: end 'do not select anything not in the date range
11 ------- - - - - - - - - - - - - - - - -
If: 'other selections can be added here
Then: select; end
12 --------------- Process
END ----------
This report offers a good sample of how to get the earliest and latest date, understood for 2 digit year date fields.
Written by Nancy Palmquist at nlp@vss3.com
Copyright, 2002 by Virtual Software Systems. All rights reserved.
Written by Nancy Palmquist
Copyright, 1997 by Virtual Software Systems. All rights reserved.