Solved

Validation of a Textbox for time input

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

761 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