
Very simple question - PLEASE HELP !!! :-)
These are two functions I use to determine the date and time values for a
given input. If the result is and empty string or vbNullString, then the
entry is invalid.
'----------------------------------------------------
' Description:
' Convert a given string into a valid date.
'
' Inputs:
' SourceText = string to be converted to a date
'
' Returns:
' TextToDate = date value of the string
'----------------------------------------------------
Public Function TextToDate( _
ByVal SourceText As String) As String
If IsDate(SourceText) Then
TextToDate = DateValue(SourceText)
Else
TextToDate = vbNullString
End If
End Function
'----------------------------------------------------
' Description:
' Convert a given string into a valid time.
'
' Inputs:
' SourceText = string to be converted to a time
'
' Returns:
' TextToTime = Time value of the string
'----------------------------------------------------
Public Function TextToTime( _
ByVal SourceText As String) As String
If IsDate(SourceText) Then
TextToTime = TimeValue(SourceText)
Else
TextToTime = vbNullString
End If
End Function
--
John Tabor
http://members.bellatlantic.net/~jftabor
___________
Quote:
>This should be easy for most of you. I'm writing a simple, little VB5
>app. that adds two times together, using the DateAdd method. I simply
>want to know how to test the user's input (InputBox$) for whether or not
>they have entered a valid time (00:00:00 - 23:59:59). I'd like to trap
>the error and prompt the user with a MsgBox to tell them to do re-enter
>the time. I've got everything down but how to test the input for a valid
>time (date) format, e.g. "00:35:55". For the life of me, I can't figure
>it out. It's gotta be simple... Any help is GREATLY appreciated! THANKS,