Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Forcing users to enter four digit years
Message
From
04/03/1999 15:51:59
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00194116
Message ID:
00194187
Views:
17
>>>I'm trying to create a date class (VFP 5.0) text box that forces a user to to enter a four digit year. I thought it was going to be a piece of cake and I will knock one out in no time. I have found that I cannot trap the number of digits the user keyed in in the *valid* because FoxPro will automatically force it to 8 digits. If I try to trap it in the *keypress* I run into other problems. What if the user pressed *delete* or *backspace*? What if the user pressed *delete* or *backspace* with no text in the text box?
>>>
>>>Has anyone invented the wheel?
>>
>>I think you are going to have to handle this control as a Character data type because whenever you start testing the value of the control as a Date type, the year will always be 4-digits if SET CENTURY is ON. As a character type, you can test the length of the year part of the value. The ControlSource of the control would be left blank, but you could add a property to the control to identify the field to use for the ControlSource. You would put This.Value = to the value identified in the new source property in the Refresh. Then in the LostFocus you could do a Replace command to repopulate the data source with the control's new value. Using the DTOC() and CTOD() functions.
>
>
>mark,
>
>Thanks for you response. I was trying to avoid handling it as a character because of the additional date and leap year validation requirements.

Validation of wrong character input is not really burdensome. You just apply CTOD() to concatenate string and if the result equals to {} it means invalid input.
Edward Pikman
Independent Consultant
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform