Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid date error...

Status
Not open for further replies.

Neil Toulouse

Programmer
Mar 18, 2002
882
GB
Hi!

I have a date field whose CONTROLSOURCE is mapped to a form property, which is initialised as an empty date {}.

If an invalid date is entered ( eg 25/25/06 ) it simply stops the focus being shifted until corrected.

However, an out of range date ( eg 10/10/1066 ) throws a FoxPro error "Date/datetime evaluated to an invalid value".

How do I trap this error as the VALID event is not fired (from what I can tell)?

Many thanks
Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Put this in VALID event:
Code:
RETURN VARTYPE(this.value) == [D]


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Neil,

I have the following code in my error-handler:

Code:
CASE tnErr = 2034
  * Invalid date or datetime during data entry
   lcMess = "Invalid date or time format. Please try again"
.......
......
	
ENDCASE

....

MESSAGEBOX(lcMess)
RETRY

That said, I've never understood why an "out of range" date is different from any other invalid date. In your example, in what sense is 10/10/1066 considered out of range?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Guys!

bborisov: The valid event doesn't fire before the error message is shown, so no use putting code there!

Mike: Thanks for that, I will give it a go and let you know. I have no idea why 10/10/1066 is invalid! I have tried it on other date fields just incase it was a weird error on this particular field, but it happens on those also!

I like work. It fascinates me. I can sit and look at it for hours...
 
Are you sure?
Then try this:
Code:
oForm = CREATEOBJECT([Form1])
oForm.Show(1)





DEFINE CLASS form1 AS form


    DoCreate = .T.
    Name = "form1"


    ADD OBJECT text1 AS textbox WITH ;
        Alignment = 3, ;
        Value = {}, ;
        Height = 23, ;
        Left = 73, ;
        Top = 29, ;
        Width = 100, ;
        Name = "Text1"


    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 83, ;
        Left = 83, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Command1", ;
        Name = "Command1"


    PROCEDURE text1.Valid
        RETURN VARTYPE(this.Value) == [D]
    ENDPROC


ENDDEFINE

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Borislav,

I tried your code. I'm seeing exactly the same result both with and without that line in the Valid.

In any case, I would have thought that, if the text box was bound to a date field, the Vartype would always return [D]. (But what do I know?)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
in what sense is 10/10/1066 considered out of range?
That to me is the question. Fox has no problem with:
Code:
?{^1066/10/10}
?Date(1066, 10, 10)
Could there be something else going on?

pamela
 
You are right Mike,
Not a good example.
The strangest thing is that this always worked for me. After your post I figured out WHY! So thank you Mike:
I have a class that I add in all my forms. In it I have:
Code:
SET DATE TO GERMAN
SET CENTURY ON
SET CENTURY TO 19 ROLLOVER 50

So if you try:
Code:
SET DATE TO GERMAN
WAIT WINDOW DATE(1066,1,1)
You will get correct result.


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
I suspect the issue of 10/10/1066 being invalid is that the machine is using the Short Date or Long Date notation. Those have a much shorter valid time span than others.

Tamar
 
Tamar I think you may have cracked the nut here!

Can you give any more specifics about the valid range for short/Long dates?

I never mentioned it as I didn't think it would even enter the equation at this point but the format is set to long date on the box!! (YL)


I like work. It fascinates me. I can sit and look at it for hours...
 
From HELP:

When SET DATE is set to SHORT or LONG, a date before {^1601-01-01} is invalid and generates an error.


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top