Write a bulletproof date validation routine. Neo Posting Freak Posts: 1,845 Threads: 44 Joined: Aug 2002 10-29-2004, 02:28 PM Quote:Looks interesting. Give me some time to run a test on it (more than 20 minutes) like I did with Meg's solution. I'll get back to you. So, how's it getting along? I hope it works (although it might be a bit slower than Meg's solution, due to the fact I implemented more checks) I'm glad the solution looked interesting Quote:Orthoganality is like the concept of independence in statistics, as well as a concept from gemotry I think . Object orientated libraries are a prime example of this - plug it in, read the API documentation, code your use of it. Performance gains using this method are huge Exactly I'm not experienced in statistics, but in geometry e.g. most axis systems are orthogonal. Code:```y ^ | | | | +--        x```The common Carthesian coordinate system is orthogonal as well. When you have coordinate in this coordinate system, like (1,1), changing the x-value of this coordinate (i.e. sliding it left/right), doesn't affect the y-value of the coordinate. And vice versa changing the y-coordinate doesn't affect the x-coordinate. Carthesian is orthogonal. Now you'd say, aren't all axis systems orthogonal? No, like this para-carthesian: Code:```y       _      /|     /    /   / +--        x```In this coordinate system, the y-coordinate is the intersect y-value of the perpendicular line through the y-axis. In this case, if you change x, y changes as well, and vice versa. Of course, OOP was invented to increase orthogonality Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 10-30-2004, 11:13 PM NEO: Ok, I ran the same test on your version as with Meg's, and it ran without any errors. Congrats! I don't like your code for computing days in month. It works, but I consider it to be extremely complex. What's wrong with a table of days per month like in Meg's final version? Even a Cobol programmer could understand that. :wink: MEG: Yes, this thread has become like a programmers' cocktail party --- who can impress who. ***** Neo Posting Freak Posts: 1,845 Threads: 44 Joined: Aug 2002 11-01-2004, 01:21 AM Moneo: Thanks for testing! I'm glad it worked perfectly! I know you don't like my super-binary-logic-days-in-month-computation, I already expected it Ok, to make you happy... [syntax="QBasic"]SELECT CASE Month CASE 1, 3, 5, 7, 8, 10, 12: MaxDays = 31 CASE 2: MaxDays = 28 - IsLeapYear CASE 4, 6, 9, 11: MaxDays = 30 END SELECT[/syntax] Everyone can indeed understand this... Perhaps even a Cobol programmer... Quote:Yes, this thread has become like a programmers' cocktail party --- who can impress who. Sorry. I just had to bring in something Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 11-01-2004, 04:29 AM Neo, I really like your CASE MONTH solution. Can I borrow it next time I need it? Thanks. ***** Z!re Posting Freak Posts: 3,522 Threads: 189 Joined: Dec 2003 11-01-2004, 04:43 AM Quote:Neo, I really like your CASE MONTH solution. Can I borrow it next time I need it? Thanks. ***** Only in the qmmunity would you see such a thing... Publicly posted code, and people asking for permission to use it. Only in the Qmmunity... Neo Posting Freak Posts: 1,845 Threads: 44 Joined: Aug 2002 11-01-2004, 12:13 PM Quote:Neo, I really like your CASE MONTH solution. Can I borrow it next time I need it? Thanks. ***** Of course, go ahead But make sure the IsLeapYear variable is either -1 (TRUE) or 0 (FALSE). If you don't know this sure, you can use this line instead: [syntax="QBasic"] CASE 2: MaxDays = 28 + ABS(IsLeapYear)[/syntax] Use the code when you deem necessary (Woohoo! Moneo wants some of my code! ) Quote:Only in the qmmunity would you see such a thing... Publicly posted code, and people asking for permission to use it. Only in the Qmmunity... Only here... Neo Posting Freak Posts: 1,845 Threads: 44 Joined: Aug 2002 11-01-2004, 04:14 PM Just a note, ToohTooh posted a similar solution in the 14th post on the first page of this thread: [syntax="QBasic"]SELECT CASE Mo CASE 1, 3, 5, 7, 8, 10, 12: MaxDayForMonth = 31 CASE 4, 6, 9, 11: MaxDayForMonth = 30 '-- Sniff the leap year case for February. CASE 2: IF (IsALeapYear(Ye)) THEN MaxDayForMonth = 29 ELSE MaxDayForMonth = 28 '-- Think about below: ' Q: Why 100 but not 99? A: Tokenize() will have trapped it. ' Q: Do we need it? A: Both yes and no. Think. CASE ELSE: MaxDayForMonth = 100 '>> Just being safe... END SELECT[/syntax] I just found out a few minutes ago. The URL is http://forum.qbasicnews.com/viewtopic.php?p=80848#80848 ToohTooh: I hope you understand. ToohTooh Junior Member Posts: 24 Threads: 1 Joined: Jun 2004 11-01-2004, 04:54 PM Your watchful eye, enthusiasm on computing, and deep knowledge should be not called a divine model, but what?.. "Keep walking..." Don't interrupt me while I'm interrupting." - Winston S. Churchill Neo Posting Freak Posts: 1,845 Threads: 44 Joined: Aug 2002 11-01-2004, 04:57 PM Thanks ToohTooh for your inspiring information. Btw, wasn't "Keep walking" from "Johnny Walker"? Or how was he called? dark ninja Junior Member Posts: 12 Threads: 3 Joined: Nov 2004 11-20-2004, 06:10 AM I have no idea what you all are talking about now, but my program's worked on everything I've tried so far. Code:```SUB DateVerify(FullDate\$) IF LEN(FullDate\$) <> 8 THEN PRINT "Invalid": END year\$ = LEFT\$(FullDate\$, 4) month\$ = MID\$(FullDate\$, 5, 2) day\$ = RIGHT\$(FullDate\$, 2) year = VAL(year\$) month = VAL(month\$) day = VAL(day\$) IF year <> INT(year) OR month <> INT(month) OR day <> INT(day) THEN PRINT "Invalid": END IF year > 3999 OR year < 1600 THEN PRINT "Invalid": END IF month < 1 OR month > 12 THEN PRINT "Invalid": END IF day < 28 OR day > 31 THEN PRINT "Invalid": END IF month = 2 THEN   IF year / 4 = INT(year / 4) THEN     IF day > 29 THEN PRINT "Invalid": END   ELSE     IF day > 28 THEN PRINT "Invalid": END   END IF END IF IF month = 4 OR month = 6 OR month = 9 OR month = 11 THEN   IF day > 30 THEN PRINT "Invalid": END END IF PRINT "Valid": END END SUB``` I wrote the whole thing as one program, so the SUB commands might not have perfect syntax. I also made a point to not look at anybody else's work before I made mine, so any similarities in design are coincidental. 'm boycotting signatures. « Next Oldest | Next Newest »