Image of Navigational Map linked to Home / Contents / Search Getting a Date

by Ross Mack - GUI Computing
Image of Line Break

It's sometimes a little more difficult than just asking...

There comes a time in almost all projects when I can be seen returning to my desk with an extra strength coffee in one hand saying something like 'Gee, I hate dates.' Don't get me wrong, I have nothing against the fruit. What I do dislike is dealing with date type data in applications. It seems everything in an application needs dates to be in a different format. ODBC wants it one way, passthrough queries want dates specified another way, the user wants to see it displayed yet another way. Let's not even mention the reporting tool.

Well, I'm pleased to announce that help is on the way in the form of the DateX control from Peter Wone's Wombat and Me. This rather clever ActiveX control takes a slightly different route to handling user Date entry. Most date entry controls take the approach of masking the user's input, which can become restrictive and nasty to use for the user. It also may not really help to validate the input. The DateX control takes the approach of letting the user enter anything and validating afterwards. This makes the user's entry easier and seems more natural. From there one of two things can happen depending on how the control has been set up.

If the RollBackOnBadData property has been set to true when the user tries to leave the control (by tabbing to the next one or clicking elsewhere) the DateX control checks its current contents. If they do not appear to be a valid date it will roll back its contents to be the last valid date it held. For example, if you user navigates to the DateX control which holds the value "01/01/1997" and they type in "This date control is cooler than I thought" when they tab away from the control it will automatically revert to showing "01/01/1997". What the user entered was clearly not a valid date of any sort.

When RollBackOnBadData is set to False the DateX control simply checks its contents when the user attempts to leave the control and retains the focus if the current contents are not valid. The user simply cannot leave the control until its contents are valid. This can be a little confusing for the user if they are simply trying to cancel whatever they are doing because they realise they don't know what date to enter, but it certainly makes sure that no invalid dates get very far into the system.

In most other ways the DateX control looks identical to a normal textbox to the user, which is good. However, it does have some additional user functionality that might just be a boon. The following keystrokes cause the DateX control to take the following actions:

All of that is very cool and works very neatly, it also doesn't require those horrible spin buttons or similar nonsense (they always seem to be too small to get your mouse pointer on the right one).

Another cool thing is this, if the user hits End followed by PgUp and PgDn the DateX control automatically goes to the last day of whatever month the user switches to.

Another feature of the control is that it exposes its contents directly as a date with the asDate property. This property represents the equivalent of a variable of type Date or a variant (of VarType Date). You can compare and assign them directly. You can also assign directly to and from Date type fields in RecordSets. In fact the current text in the control is not directly exposed so that you are forced to deal with dates not as formatted text but as actual date values. The DateX control also always uses centuries in its years for Year 2000 compliance. Very handy.

The AutoDate property will also likely see a lot of use. This property can be used to automatically set the current Date in the control to a large number of predefined dates. Simple examples are Today, Tomorrow, Yesterday, First day of this week and last day of this month. Complex dates are also available like First Day of 2 months ago and 90 days in the future.

The DateX control is also available as TEditDate, a Delphi VCL. In fact it is from the VCL that the ActiveX version is compiled, meaning both versions come from the same code base which is good.

I think there are a couple of ways in which the control could be improved to provide better user and programmer feedback about the current state of the control (a simple Valid property to indicate whether or not the current contents are valid would be useful). It also seems to have trouble validating entries that have alpha months (eg: "1-jan-1997") but all in all the control does what it is supposed to do and it certainly makes the handling of user entered dates very simple. If you have trouble with dates (and who doesn't?) you might want to check out the downloadable trial version available from www.wamoz.com or contact GUI Computing, the distributors.

At $A69, including a bonus control, this is probably a bargain.



Written by: Ross Mack
October '97

Image of Arrow linked to Next Article
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]