The bWinToDate Function

This provides the same functionality as bWinToNum, but for dates instead of numbers:

Function bWinToDate(ByVal sWinString As String, _

ByRef dResult As Double, _

Optional bShowMsg) As Boolean

If IsMissing(bShowMsg) Then bShowMsg = True

If sWinString = "" Then

' An empty string gives a valid date of zero

dResult = 0

bWinToDate = True

Elself IsDate(sWinString) Then

' We got a proper date, so convert it to a Double

' (i.e. the internal date number)

dResult = CDbl(CDate(sWinString))

bWinToDate = True


' If not, display a message, return zero and failure

If bShowMsg Then MsgBox "This entry was not recognized as

a date," & _

Chr(10) & "according to your Windows Regional Settings.

. ", vbOKOnly

dResult = 0

bWinToDate = False

End If

End Function

sWinString is the string to be converted. dResult is the converted number, set to 0 if the number is not valid, or empty. bShowMsg is optional and should be set to True (or missing) to show an error message, or False to suppress the error message.

0 0

Post a comment