Results 1 to 6 of 6

Thread: How to check that the variable is contain Time Data or not?

  1. #1

    Thread Starter
    Hyperactive Member solar115's Avatar
    Join Date
    Apr 2002
    Location
    Thailand
    Posts
    268

    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?
    ^solaris^

  2. #2
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574
    Use the IsDate function.

  3. #3

    Thread Starter
    Hyperactive Member solar115's Avatar
    Join Date
    Apr 2002
    Location
    Thailand
    Posts
    268
    Please give me an example.
    ^solaris^

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    VB Code:
    1. If IsDate(Text1.Text) Then
    2.     MsgBox "This is a valid date/time value"
    3. Else
    4.     MsgBox "This is not a valid date/time"
    5. End If
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5

    Thread Starter
    Hyperactive Member solar115's Avatar
    Join Date
    Apr 2002
    Location
    Thailand
    Posts
    268
    Thank You
    ^solaris^

  6. #6
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574
    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
  •  



Click Here to Expand Forum to Full Width