3 Replies - 11096 Views - Last Post: 31 July 2008 - 10:50 PM Rate Topic: -----

#1 rudeman76  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 30-July 08

time in textbox

Posted 30 July 2008 - 12:30 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: time in textbox

#2 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: time in textbox

Posted 30 July 2008 - 03:16 AM

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.
Was This Post Helpful? 0
  • +
  • -

#3 tope10  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 23
  • Joined: 26-June 08

Re: time in textbox

Posted 31 July 2008 - 12:49 AM

View Postrudeman76, on 30 Jul, 2008 - 12:30 AM, said:

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.

Was This Post Helpful? 1
  • +
  • -

#4 rudeman76  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 30-July 08

Re: time in textbox

Posted 31 July 2008 - 10:50 PM

:^: Thanks for all your help. I used the dtpicker and it worked. Thanks again. I greatly appreciate it
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1