January 20, 200520 yr I have script with a Show Custom Dialog allowing the user to change a date. The actual date being changed in the dialog is a global date field, which I will set to the final date field when the date has been validated. I have already detected if they try to enter nothing - If IsEmpty(gDate), then fail. But I don't know how to detect an invalid date. I tried inserting an If Status(CurrentError) = 500, but it doesn't trigger when it should. Any ideas?
January 20, 200520 yr I use global text fields for date entry, because invalid ones are not allowed in global date fields. And if you have Set Error Capture [On], no error message will be returned when an invalid one is entered, but the script will still fail once you attempt to exit the record. Using a global text field makes it easy. You can use If [isValid(TextToDate(gText))] to test the result, without the nasty side-effects. This, of course, means users must enter a 4-digit date, but that should be standard practice already.
January 21, 200520 yr Author Excellent suggestion. I am now using the text field and using this validation on it before I proceed with my script: If [(not IsValid(TextToDate(temp_global_text_4))) or (Length(temp_global_text_4) 10)] I tested using the two-digit year, but when I tried changing 12/26/2004 to 12/27/04, it actually changed it to 12/27/1904. So, that's why I added the Length(gText) function to catch for that. I know that FileMaker 6 went through a couple revisions involving the date format, but I know that I have to add that length function on my FileMaker 6.0v4 Dev version.
January 21, 200520 yr Author Darn, I just realized that the 10 digit length won't work for dates like 1-1-2005, 1-15-2005 or 10-8-2005. I think this works better: (not IsValid(TextToDate(temp_global_text_4))) or (Length(RightWords(temp_global_text_4, 1)) 4)
January 21, 200520 yr I have another suggestion - not littering a solution with globals: If [ IsEmpty ( Get ( ScriptParameter ) ) xor IsEmpty ( Untitled::DateEntry ) ] Perform Script [ "Validate Dialog"; Parameter: Untitled::DateEntry ] Else Show Custom Dialog [ Title: "Hola amigo"; Message: "Please enter a new date"; Buttons: "OK"; Input #1: Untitled::DateEntry ] If [ not IsValid ( Untitled::DateEntry ) ] Show Custom Dialog [ Title: "Error!!!"; Message: "Invalid entry...the value is returned to it's previous state"; Buttons: "OK" ] Set Field [ Untitled::DateEntry; Get ( ScriptParameter ) ] End If End If Where second line is a recursive call!!! --sd
January 21, 200520 yr Oh I appologise, then do you have to use the global JT mentioned - sorry for the inconvenience caused! --sd
January 21, 200520 yr Author Hey no problem - I was half-way through the implementation so I don't think I would have switched to another method anyway.
January 21, 200520 yr Actually, I was wrong about the 4-digit year necessity. I also use a script to convert years that may fall under the wrong century. The only validation that should be necessary is If [not IsValid(TextToDate(temp_global_text_4))] or IsEmpty(temp_global_text_4)] If this validation passes, set your date field with TextToDate(temp_global_text_4) and then If [Year(datefield) < 1990], Set Field [datefield, Date( Month(datefield), Day(datefield), Year(datefield) + 100 )], substituting your lowest year for 1990.
January 21, 200520 yr Author Nah... I'd rather force my users to enter 4 digit years. It's a good habit to get into. Plus I wouldn't have to update my script the next century around.
January 21, 200520 yr What about using a date plugin? That way the date format would always be the same. A bit costly but it solves the problem of having to code your own date validation routine. The Mad Jammer
Create an account or sign in to comment