diff options
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/scriptforge/SF_String.xba | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/wizards/source/scriptforge/SF_String.xba b/wizards/source/scriptforge/SF_String.xba index 66eb90910ba5..23010e88c750 100644 --- a/wizards/source/scriptforge/SF_String.xba +++ b/wizards/source/scriptforge/SF_String.xba @@ -719,7 +719,10 @@ Public Function IsADate(Optional ByRef InputStr As Variant _ Dim bADate As Boolean ' Return value Dim sFormat As String ' Alias for DateFormat -Dim sRegex As String ' The regex to check against the input string +Dim iYear As Integer ' Alias of year in input string +Dim iMonth As Integer ' Alias of month in input string +Dim iDay As Integer ' Alias of day in input string +Dim dDate As Date ' Date value Const cstFormat = "YYYY-MM-DD" ' Default date format Const cstFormatRegex = "(YYYY[- /.]MM[- /.]DD|MM[- /.]DD[- /.]YYYY|DD[- /.]MM[- /.]YYYY)" ' The regular expression the format must match @@ -743,10 +746,14 @@ Check: Try: If Len(InputStr) = Len(DateFormat) Then - sRegex = ReplaceStr(sFormat, Array("YYYY", "MM", "DD") _ - , Array(REGEXDATEYEAR, REGEXDATEMONTH, REGEXDATEDAY) _ - , CaseSensitive := False) - bADate = SF_String.IsRegex(InputStr, sRegex, CaseSensitive := False) + ' Extract the date components YYYY, MM, DD from the input string + iYear = CInt(Mid(InputStr, InStr(sFormat, "YYYY"), 4)) + iMonth = CInt(Mid(InputStr, InStr(sFormat, "MM"), 2)) + iDay = CInt(Mid(InputStr, InStr(sFormat, "DD"), 2)) + ' Check the validity of the date + On Local Error GoTo NotADate + dDate = DateSerial(iYear, iMonth, iDay) + bADate = True ' Statement reached only if no error End If Finally: @@ -755,6 +762,9 @@ Finally: Exit Function Catch: GoTo Finally +NotADate: + On Error GoTo 0 ' Reset the error object + GoTo Finally End Function ' ScriptForge.SF_String.IsADate REM ----------------------------------------------------------------------------- |