×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Entering and validating a 2-digit month

Entering and validating a 2-digit month

Entering and validating a 2-digit month

(OP)
I am revisiting some old code. There is a 2-digit text box which is to specify a month. So ‘03’ would represent March. What is other users' practice for specifying the properties of such a field on the form, and for validating it?

Thanks - Andrew

RE: Entering and validating a 2-digit month

I don't use separate fields for day, month and year, but either a calendar control or a single field for a date, which includes validation simply by data type.

If you'd separate this the month validation is simple, unless you take the day into account, because if it is 31, not all months are valid, even 29 could depend on the year, when it comes to February because of leap days. So why not rely on the date type taking care of this?

PS: In the bigger picture, consider validating the whole form instead of validating each single control. Some checks to make a record valid also require to compare two fields, that can only be checked in a wholesome way anyway, a three part date entry is agood example, as already teased with some special cases, in the end any input could turn out to be right, when finally day, month, and year are entered, while the day, month, or year could result in a wrong date during the input of the date parts, so why waste individual checks? The limits 1-31, 1-12 and maybe even a lower and upper year (spinner control) could guide the use to not get into ridiculous values territory, but the date check in the end is an overall check whether DATE(year,month,day) is a valid date.

Chriss

RE: Entering and validating a 2-digit month

andrew,

What exactly are you asking here? Clearly, you already know how to check that a given number is a valid month number. You simply check that it lies between one and 12. So I assume there is more to your question than that.

Your mention of "03" as an example value suggests that the textbox is of character type. If it was numeric, the leading zero would not exist: the number would simple be 3. If it is a character string, why?

Is the month number just a field on its own? Or is one of several fields that together represent a complete date? If the latter, is there a good reason for not simply using a date or datetime data type?

Finally, you say this is old code. Presumably it is code that has been working up to know. If so, why do you need to change it?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Entering and validating a 2-digit month

(OP)
Thank you Chris and Mike, for your replies.

To Mike’s point, I am revisiting an old report to make a new version with different options. The control into which I am entering the month is not part of a date : it is just part of specifying a range for the report.

The control used to just have an input mask of ‘99’ and the validation routine did not alter the displayed value.
I am now considering changing the validation method to include :

CODE -->

WITH Thisform
   This.Value = RIGHT(STR(VAL(This.value) + 100,3),2)
   ENDWITH
RETURN .T. 

So that this means that when the user keys in ‘3’ <Enter>, the control shows ‘03’ on the screen. I just wondered if there was a way of doing this by specifying one of the properties of the control.

I just wondered if there was a way of organising this by specifying one of the properties of the textbox. It’s not a big thing!

Thanks again.

RE: Entering and validating a 2-digit month

For padding you have the pad functions, no need for such complicated trickery. Why insist on a 2 digit display anyway?

Even if this is month standalone you'd want to check it's betwenn 01 and 12 only, for that a spinner is the best control.

Chriss

RE: Entering and validating a 2-digit month

Quote:

when the user keys in ‘3’ <Enter>, the control shows ‘03’ on the screen.

But why do you need to do that? Why not just let them enter "3"? That would work regardless of whether the field is numeric or a character string. You would then just need to check that it is in the range 1 - 12.

Chris suggested using a spinner. Personally, I'm not that keen on spinners. But if you do decide to do that, you can do the validation simply by settings its KeyboardHighValue, KeyboardLowValue, SpinnerHighValue and SpinnerLowValue properties.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Entering and validating a 2-digit month

Quote (Mike Lewis)

I'm not that keen on spinners
Why, you can still use the textbox portion as a textbox.

Chriss

RE: Entering and validating a 2-digit month

As well as the textbox and spinner, there is a third option: a combo box. You could use a combo box that displays the actual names of the months, and let the user pick the one they require. The ListIndex property would then give you the month number. No validation required.

This might or might not be the best approach. It would depend on your users' preferences. But it's something to consider.

(If you did decide to use a combo box, setting its IncrementalSearch property .T. would be a good move.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close