|
-
Jul 5th, 2016, 03:31 PM
#5
Re: DateDiff() result differs on 1st run and succeeding runs?
I'm adding a third hunch the DateTimePickers aren't unchanged like you think. Here's some other thoughts.
You say you expect a 1 or a 0, but when I read over your code I don't see how you decide you're getting a 1 or a 0. The only side effect of this code I see is you call HighlightError() with the results of concatenating some strings. That, in and of itself, seems really weird.
I can only guess that, for certain inputs, you're not getting the result you expect. But your If statements confuse me. Some of this is because DateDiff() is unfamiliar, it's not part of the average .NET developer's toolbox. I think you could probably restructure your code to accomplish the same thing with clearer techniques.
For example:
Code:
If DateDiff(DateInterval.Day, Date.Now.Date, dtpBirthdate.Value.Date) > 0 Then
I think this says, "If there are a positive number of days between Date.Now and the given birthday..." The sense of this is, "I want to know if the birthdate is earlier than today." You can more clearly state this like so:
Code:
If Date.Now < dtpBirthdate.Value.Date Then
That's closer to the intent. "If today is less than the birthday..." is a lot better than "If calling DateDiff() given these parameters gives a value greater than one..."
Consider dropping DateDiff() from your toolbox and adopting this technique of comparing dates. "If date1 < date2 Then" is easier to type and maintain than "If DateDiff(DateInterval.Day, date1, date2) < 0". Maybe that'll make this bug go away. But part of me doubts it, I think there's probably some odd interaction with the pickers you haven't anticipated. For example, if HighlightError() changes one of the values, even slightly, it could impact the behavior.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|