Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A little tip for editing date values in a textox 5

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I just came across this while perusing some old notes, so I thought I would share it. It could be you all already know this, but in case you don't ....

You have a form containing a textbox. The textbox is of type Date (that is, it is either bound to a Date field or you set its initial Value to a date). The user can edit the date in the usual way by positioning the insertion point and typing in the appropriate numbers. So far, so good.

But did you know that the user can also highlight the entire date, then press + (plus). This will increment the date by one day. After you have done this, the date remains highlighted, so you can press + repeatedly to keep incrementing the date.

In exactly the same way, pressing - (minus) will decrement the date by one day. (It also works with DateTimes.)

This happens by default, in the native textbox. If you set the Format property to K in your base textbox class, the date will be highlighted as soon as the user tabs to it, which makes life a little bit easier.

Of course, many of us use some sort of drop-down calendar with our date fields, but if you just use a plain textbox, this little tip might be worth keeping in mind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Nice mike! thanks.... but i came across with this problem with date mike, please help.... i had a program that expires when a certain date is reach... so i change the date of my laptop to test whether it will show a message of expiration, and so it did... but when i try to edit the code, the output does not change anymore... even if i put errors on it, it run on the last output... nothing is happening even if i edit the program code... what happened? please help... thanks....
 
Mandy,

Please start a new thread for this question. If you simply tack it on to the end of this thread, it is likely to go unnoticed.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok... Thanks mike...
 
That is really interesting Mike, do you remember how you found it?

I usually program the F8 key to put today's date wherever the cursor is, and put buttons / right clicks for calendar, this week, next week etc.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Jeez, that's indeed a new one O.O

I build my date-textbox class many years ago and implemented + and - explizitly *sigh*

The VFP guys could have made it even more usefull if they had activated some other keys, too

PGUP = month +
PGDN = month -
POS1 = 1st of month
END = last of month
C = current day
A = + 2 days
D = - 2 days
W = + 7 days
S = - 7 days
Q = 1st of year
E = last of year

It would have spared me some code :) :) :)

BTW: Before you ask why I used C A D W S Q E, they are nicely placed on the keyboard for this ;)


-Tom
 
Great find, Mike.

actally, it works also if you don't set the Format property to "K", but use the SelectOnEntry property.
 
Nice one Mike. Did NOT know this!

Also, thanks for the list of keys Tom!


Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"I try to be nice, but sometimes my mouth doesn't cooperate.
 
Thank you all for your feedback. It's gratifying that this tip was new to you all. When sharing this kind of information, I often worry that it is something that everyone already knows, and the reaction will be, "Yeah! Now tell us something we don't know."

Griff, you asked how I found this. I'm fairly sure it was in an article in either FoxPro Advisor or FoxTalk, many years ago. I noted it down at the time, and then forgot about it, until I was perusing some old notes the other day.

Tom, interesting to hear about your date textbox class. But you weren't wasting your time by implementing the plus and minus keys yourself, as the native behaviour only kicks in when the entire field is highlghted. If your version increments and decrements the day, month and year separately, that would be added value.

Come to think of it, I think Tamar wrote an article once in which she described a similar class, with shortcut keys to set the date to today, yesterday, first of month, last of month, and so on. It might have been the same FoxPro Advisor or FoxTalk article I mentioned above. Unfortunately, I don't know when or where that was. I have back copies of both journals in paper form, but I don't have an electronic copy or an index that I can search. (Tamar, if you happen to see this, perhaps you can jump in.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Honestly, I created the class many years ago and I use the shortcuts all the time. But I noticed, that no one but me used the features.
Mostly every user is using my calendar and time class. :)

The cal and time classes have been visually modified over the years but the basic features have been more or less untouched.
caltimedemo_pt0u8i.jpg


-Tom
 
Tom, well done on creating those two classes. They look very smart.

I once developed my own drop-down calendar, but it had a mysterious bug. I'll describe the behaviour, and let's see if anyone can identify the problem - before you read the spoiler in the last paragraph in this post.

The calendar was based on a form without a title bar, and therefore without a Close button. I reasoned that it would be easier for the user to simply click anywhere outside the calendar in order to dismiss it. To achieve that, I simply put [tt]THISFORM.Release[/tt] in the calendar's Deactivate event.

Most of the time, that worked perfectly. But in some cases, clicking outside the calendar had no effect; the user was unable to close the calendar. Eventually, it dawned on me why this was happening. In fact, the answer was completely obvious. It was stupid of me to have seen it. Can you see where I had gone wrong?

Spoiler: The answer is simple. In the cases where the calendar couldn't be closed, I had placed it on a modal form. The calendar itself was modeless, but - as you know - if a modal form calls another form, that other form becomes modal, regardless of its WindowType setting. And given that it was now modal, clicking outside the form doesn't fire its Deactivate. Simple when you know the solution.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, I know those problems. :)

Did you ever find a way of getting the calendar closed without clicking an exit button?

Thank god we rarely stumble upon this as most of our main forms are modeless and the few that are modal don't have date/time input. Well, till now...who knows what the future might bring up. SO it would be good to know that there is a solution around for that.

-Tom
 
Tom, the solution I adopted was simply to add a small Close button to the form: just a normal command button, with a large X in it. This had code to release the form. So, for most of the time, the user could close the form either by clicking outside it or by clicking on the button. When the form was modal, they could only click on the button. I didn't get any negative feedback from the users, so I assume they were happy with it.

I did consider making the button invisible when the form was modeless, but I was worried that some users might have found that slightly confusing.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Tamar,

You're right. It was that article.

I see it was 15 years ago since the article appeared. I can't tell you how pleased I am that my memory hasn't completely failed me yet.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I had only the vaguest memory of having written that. If I didn't have my articles on my website, I doubt I would have remembered it.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top