|
-
Jun 25th, 2003, 11:30 PM
#1
Thread Starter
Hyperactive Member
How to check that the variable is contain Time Data or not?
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?
-
Jun 26th, 2003, 01:23 AM
#2
Fanatic Member
-
Jun 26th, 2003, 01:31 AM
#3
Thread Starter
Hyperactive Member
Please give me an example.
-
Jun 26th, 2003, 02:31 AM
#4
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
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Jun 26th, 2003, 03:50 AM
#5
Thread Starter
Hyperactive Member
-
Jun 26th, 2003, 04:20 AM
#6
Fanatic Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|