Solved

Validation of a Textbox for time input

Posted on 2011-09-27
4
1,708 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 47

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

732 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