ScreenIO allows a zero date initially because initially your code is setting it (or in this specific case, your code is not setting it and everything defaults to 0). Validation Routines (even automatic ones like DATE) don't run until the user changes the value.
However, the good news is you can accomplish what you're trying to do with a simple validate function. I've written one and included it in this post.
1) download it and put it in your "function" folder.
2) Then select it as the validate function for date fields that you want to allow 0 in.
3) Finally, put the date mask in both
your Conversion and Userdata fields.
If you look at the source code below, you can see how it works.
The first thing I do is have a comment explaining how to use the function. Thats pretty important because it can be easy to forget when months or years go by and I need to use the functionality for another customer in another application.
The function is simple - it checks to see if the date entered is zero. If its zero, then it temporarily clears the Conversion spec suspending ScreenIO's automatic date processing. If the entered data is anything other then zero, it sets the Conversion spec back, enabling normal ScreenIO automatic date processing.
Code: Select all
! Created on 09/07/2013
! fnValidateDateAllowZero - This Function is for fields with Dates
! where 0 is a valid date. If 0 is detected, normal date processing
! is suspended. If 0 is not detected, normal date processing proceeds
! as usual. Put your Date spec in both the Conversion and UserData
! fields, in order for this to work properly.
if trim$(FieldText$)(1:1)="+" or trim$(FieldText$)(1:1)="-" then
let Number=val(fieldtext$) conv Ignore
if Number=0 then