Link to home
Start Free TrialLog in
Avatar of AWestEng
AWestEngFlag for Sweden

asked on

Check if string is valid time

Hi

How can I chak for a vaild time and only for a time

DIm strTIme as string = "16:34"

 If IsDate(strTIme ) And strTIme .Length = 5 Then
     'OK
else
    'Fault
End if

The probelm is that is also takes a date 05/05 => OK

How can I check that so it only approve the string if it's vaild time?
SOLUTION
Avatar of adriankohws
adriankohws
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AWestEng

ASKER

I found this.. but is's somethinh wrong with it

    Public Function IsTime(ByVal Time As Object) As Boolean
        '*****************************************************************
        '* This subroutine determines if a value is a valid time
        '* (not  date).
        '************************************************************

        If IsDate(Time) = True Then
            If CStr(Time) Like "*#*.*#*" = False Then
                If Fix(CDate(Time)) = 0 Then
                    If CStr(Time) Like "1[3-9]*[aApP]*" = False Then
                        If CStr(Time) Like "2[0-3]*[aApP]*" = False Then
                            IsTime = True
                        End If
                    End If
                End If
            End If
        End If

    End Function
SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial