Qbasicnews.com

Full Version: Write a bulletproof date validation routine.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
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) Wink I'm glad the solution looked interesting Smile

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 Wink 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.
Wink
Of course, OOP was invented to increase orthogonality Wink
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.

*****
Moneo:
Thanks for testing! Wink I'm glad it worked perfectly!
I know you don't like my super-binary-logic-days-in-month-computation, I already expected it Smile
Ok, to make you happy... Wink
[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... Wink 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 Wink
Neo, I really like your CASE MONTH solution. Can I borrow it next time I need it? Thanks.
*****
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... Smile
Quote:Neo, I really like your CASE MONTH solution. Can I borrow it next time I need it? Thanks.
*****
Of course, go ahead Big Grin 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 Wink (Woohoo! Moneo wants some of my code! Big Grin)

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...
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.
Your watchful eye, enthusiasm on computing, and deep knowledge should be not called a divine model, but what?..

"Keep walking..."
Thanks ToohTooh for your inspiring information. Wink

Btw, wasn't "Keep walking" from "Johnny Walker"? Or how was he called? Tongue
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.
Pages: 1 2 3 4 5 6