Solved

Validation of a Textbox for time input

Posted on 2011-09-27
4
1,562 Views
Last Modified: 2012-05-12
i need to enter a time in 24 hour format into a textbox.  im using the masked edit contol with a format of ##:##

im getting an error with an entry of 44:44 for obvious reasons

is there a function for vb6 that can limit the input to valid time ranges?

0
Comment
Question by:rmardis
4 Comments
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 36714333
There is an IsDate function that you could use (because Time is considered a part of Date).  

But the way you would use it is once the user inputs the data, you would test the text to see if it passes for a valid date/time string and display a message box if it doesn't.

Otherwise, you have to apply your own logic in something like the textbox's KeyPress event.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 36714531
Another option would be to supply a combobox with acceptable times or one combobox with hours and another with minutes connected by a label whose caption is a colon.
0
 
LVL 1

Accepted Solution

by:
dhayzen earned 500 total points
ID: 36715572
Another option is to use a MaskEdBox.

Set mask to ##:##.

Then validate the values after input...

e.g.

Public Function IsTime(ByVal t As String) As Boolean
On Error Resume Next
'Is t a valid time ???

'Correct Length ??
If Len(t) <> 4 Then Exit Function

'HHnn numeric ??
If IsNumeric(t) = False Then Exit Function

'Check minute value
If Val(Right(t, 2)) < 0 Or Val(Right(t, 2)) > 59 Then Exit Function

'Check hour value
If Val(Left(t, 2)) < 0 Or Val(Left(t, 2)) > 23 Then Exit Function

IsTime = True
End Function
0
 

Author Closing Comment

by:rmardis
ID: 36716235
works like a charm, Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now