If I have some TextBox that I want user to fill in the time value.
How can I check the value that user filled in is time value or not?
Printable View
If I have some TextBox that I want user to fill in the time value.
How can I check the value that user filled in is time value or not?
Use the IsDate function.
Please give me an example.
VB Code:
If IsDate(Text1.Text) Then MsgBox "This is a valid date/time value" Else MsgBox "This is not a valid date/time" End If
Thank You
Our company network link had been down for the last two hours or so now, hence the delay. I've been trying since then to send you this code.
Here, use this nifty function.
Code:Private Sub Command1_Click()
If IsTime(Text1.Text) Then
MsgBox "You've entered a valid time value.", vbInformation, "Value Accepted"
Else
MsgBox "Please enter a valid time value.", vbCritical, "Invalid Time"
If Text1.Enabled Then Text1.SetFocus
Exit Sub
End If
End Sub
Public Function IsTime(ByVal StrTemp As String) As Boolean
Dim StrShortTime As String
IsTime = False
StrTemp = Trim(StrTemp)
If StrTemp = vbNullString Then Exit Function
If IsDate(StrTemp) Then
StrShortTime = FormatDateTime(StrTemp, vbShortTime)
If StrShortTime = "00:00" Then
If (Not (InStr(1, StrTemp, "0:00") > 0)) Or (Not (InStr(1, StrTemp, "00:00") > 0)) Then
Exit Function
Else
IsTime = True
End If
Else
IsTime = True
End If
Else
Exit Function
End If
End Function