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
Solved

Validation of a Textbox for time input

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

808 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