Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 109,567 VB Programmers for FREE! Ask your question and get quick answers from experts. There are 1,436 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



time in textbox

 
Reply to this topicStart new topic

time in textbox

rudeman76
post 30 Jul, 2008 - 12:30 AM
Post #1


New D.I.C Head

*
Joined: 30 Jul, 2008
Posts: 3

hi,
I have a textbox(txtTime) that the user enters in a time. I do not know how to make it so the user can only enter in valid times. I have tried using a Masked Edit Control and set the mask to ##:## and set the format to hh:mm. I can still enter in invalid times (eg. 36:23). I have tried just using a textbox, but cannot figure out how to make it work. I want the box to only show " : " and thats it. If the user does not enter in a time, then the current time will automatically be entered. I have been told to use the dtpicker control, but I do not want them to pick the date (I have never used this function and not aware if it can just accept time). Any help you can be is greatly appreciated. Sorry i dont have any code as i just set the info in the properties. I am using VB6.

It has been awhile since i have used VB. I have recently programmed in VBA for Access. In there when you enter in the format of time on a textbox, it automatically makes the user enter in a valid time. I would like to be able to do this.

Rude
User is offlineProfile CardPM

Go to the top of the page


Zhalix
post 30 Jul, 2008 - 03:16 AM
Post #2


D.I.C Head

**
Joined: 7 May, 2008
Posts: 217



Thanked 9 times
My Contributions


Well, I don't know about the date picker or anything, but if you're trying to do this with a simple textbox, you have several options. You could use two textboxes, like this:

[ ] : [ ]

And set the max length on both textboxes to two characters. In the keypress event, make it so that they can only enter numbers. Then, in the button or wherever you're validating the time, just check if the first textbox is greater than 0 and less than 13. In the second textbox, check to see if it's simply less than 60. If the time is valid, then combine the text in both textboxes, but put a colon between them.

If you're going to use one textbox, set the max length to 4, and then allow them to only enter numbers and also a colon. Then, when validating the time, check if a colon exists, and if that's the case, that there is only one colon. If this is true, then check to see if the numbers on the left side of the colon are valid, and the numbers on the right.

I don't know anything about the dtpicker so good luck if you go that route.
User is offlineProfile CardPM

Go to the top of the page

tope10
post 31 Jul, 2008 - 12:49 AM
Post #3


New D.I.C Head

*
Joined: 26 Jun, 2008
Posts: 20



Thanked 2 times
My Contributions


QUOTE(rudeman76 @ 30 Jul, 2008 - 12:30 AM) *

use the Dt picker control, it can be found in the components and adding the Microsoft Windows, Common Control 2-6.0.
then once you insert it in your form change the format to dtpTime.


User is offlineProfile CardPM

Go to the top of the page

rudeman76
post 31 Jul, 2008 - 10:50 PM
Post #4


New D.I.C Head

*
Joined: 30 Jul, 2008
Posts: 3

icon_up.gif Thanks for all your help. I used the dtpicker and it worked. Thanks again. I greatly appreciate it
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/7/08 11:35PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month