|
|||||||
|
|
|
|||||
|
|
|||||||
How to Perform the IsTime Function? Visual Basic has functions, IsDate, IsNumeric etc. But where is IsTime? IsTime, The routine is obviously called IsTime.
Public Function IsTime(argInputString As String) As Integer
Dim wrkString As String
Dim kk As Integer
Dim wrkStringLength As Integer
Dim wrkNumberColon As Integer
On Error Resume Next
'
' Trim a working copy of the string
wrkString = Trim$(argInputString)
'
' Set string is not a time and exit if blank
IsTime = False
If (wrkString = "") Then Exit Function
'
' Validate the string and count colons
wrkStringLength = Len(wrkString)
wrkNumberColon = 0
For kk = 1 To wrkStringLength
Select Case Mid$(wrkString, kk, 1)
Case "0" To "9"
Case ":"
wrkNumberColon = wrkNumberColon + 1
If (kk > 1) Then
If (Mid$(wrkString, kk - 1, 1) = ":") Then Exit Function
End If
End Select
Next kk
'
' Check colons
If (wrkNumberColon = 0) Then Exit Function
If (Left$(wrkString, 1) = ":") Then Exit Function
If (Right$(wrkString, 1) = ":") Then Exit Function
'
' Set string is a valid time
IsTime = True
End Function
Note : This routine assumes that you use a colon, to delimit hours, minutes and seconds. You can read the Windows Registry for any special values. The routine assumes that a blank string is an invalid time. You might think that a blank time is midnight.
Copyright (c) 1999 - 2001, robert han, all rigths are reserved.