Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Catching invalid date in text field?
Message
From
08/05/2009 11:57:23
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01398647
Message ID:
01398651
Views:
111
This message has been marked as the solution to the initial question of the thread.
Before getting to the date issue, this code has a problem. It's setting ON ERROR conditions without taking into account that a previous ON ERROR handler could already exist. It also doesn't reset the ON ERROR handler at the end. There are better ways to handle this that don't reset ON ERROR, such as TRY/CATCH or even just a message box.

To handle the date:

LOCAL llRetVal

llRetVal = .T.

IF !EMPTY(This.Value) AND EMPTY(CTOD(This.Value))
MESSAGEBOX("Invalid date")
llRetVal = .F.
ENDIF
RETURN llRetVal


>I'm receiving a text field called ExportStartDate from a SQL Server stored procedure. It is defined as a varchar(10), the default value is blank. I'm putting in into a text field on the form and set the Format to D. I put the following code in the Valid hoping to catch if they entered a date incorrectly. My goal is only to have a valid date or an empty value. I thought the CTOD() function would throw an error if the date was invalid, but it simply returns a blank date. While a blank value is valid, it's not valid if they tried to enter a date.
>
>
>LOCAL llerror 
>IF !EMPTY(this.Value)
>	ON ERROR llError=.t.
>	mDate=CTOD(this.Value)
>	ON ERROR DO errsys WITH ERROR(),MESSAGE(1),MESSAGE(),PROGRAM(), LINE(1)
>	IF llerror=.t. 
>		RETURN .f.
>	ENDIF 
>ENDIF 
>
>
>Anyone have an idea how I should approach the validation of the data?
>
>Thanks in advance
>
>Kirk
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Reply
Map
View

Click here to load this message in the networking platform