Solved

Validation of a Textbox for time input

Posted on 2011-09-27
4
1,520 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 45

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

11 Experts available now in Live!

Get 1:1 Help Now