Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7248 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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?

Posted

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.

Posted

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) notequal.gif 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.

Posted

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)) notequal.gif 4)

Posted

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

Posted

Hey no problem - I was half-way through the implementation so I don't think I would have switched to another method anyway.

Posted

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.

Posted

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. wink.gif

This topic is 7248 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.