Harry,
Here's something that works on my end:
Code:
var
dtInput, ; user's input date
dtFYBeg, ; start of the FY
dtFYEnd Date ; end of the FY
siValue SmallInt ; Control value.
loDateOK Logical ; Flag: Is Input Date OK?
strError String ; Message displayed to user.
endVar
loDateOK = FALSE ; assume failure to reduce code.
strError = ""
; First, verify that we have a date value.
try
dtInput = dateVal( self.Value )
onFail
strError = "\"" + String( self.Value ) +
"\"" + " is not a date value."
endTry
if strError = "" then ; skip; there's already an error
; Next, calculate the current fiscal year
if month( Today() ) < 10 then
dtFYBeg = DateVal( "10/01/" +
String( Year( Today() ) - 1 ) )
dtFYEnd = DateVal( "09/30/" +
String( Year( Today() ) ) )
else
dtFYBeg = DateVal( "10/01/" +
String( Year( Today() ) ) )
dtFYEnd = DateVal( "09/30/" +
String( Year( Today() ) + 1 ) )
endIf
; Verify the input date falls within
; the current fiscal year
if dtInput >= dtFYBeg then
if dtInput <= dtFYEnd then
loDateOK = true
else
strError = "Your value ( " + String( dtInput ) +
" ) falls after the end of " +
" the current fiscal year."
endIf
else
strError = "Your value ( " + String( dtInput ) +
" ) is before the start of the " +
"current fiscal year."
endIf
endIf
; Finally, evaluate the results
if not loDateOK then
beep()
msgStop( "Invalid Date", strError )
eventInfo.setErrorCode( peCannotDepart )
endIf
This particular example should work from the canDepart event of an unlabelled field object. Now, I had to make a few assumptions, but you'll note the heavy use of typecasting to get the various values into the format needed at the moment.
Also, you'll notice I used a specific error to control Paradox in the event of a bad date. When you're overriding the event model, it's best to be as specific as possible.
Finally, you'll note that I tend to use nested IF statements in Paradox. There are two main reasons for this:
1. Paradox doesn't support short-circuit evaluation; it always evaluates all operands in an expression, even when one would fail the expression.
2. Because Paradox doesn't support short-circuit eval, you need to verify that all variables actually have values that can be evaluated. You can work around this by making sure that expressions are only evaluated when there are good values. For example, I skip the date comparison when there isn't even a date variable. Had I not done that, there would have been an uninialized variable error in the comparisons.
I know some of this seems like it's really picky, but learning these quirks is part of ObjectPAL; the quirks make sense, once you understand them. Unfortunately, you don't learn them until you get burned by them and that's primarily why a lot of people get frustrated with the language.
Fortunately, you can still get good help dousing the fires.
Hope this helps...
-- Lance