Option
Explicit
Private
Const
REGEX_PATTERN
As
String
=
"[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}"
Private
Const
MAX_TRY
As
Integer
= 5
Public
Function
get_date()
As
Date
Dim
strInput
As
String
Dim
regEx
As
New
RegExp
Dim
i
As
Integer
With
regEx
.Global =
True
.IgnoreCase =
True
.MultiLine =
False
.Pattern = REGEX_PATTERN
End
With
Do
i = i + 1
If
i = 1
Then
strInput = InputBox(
"Bitte geben Sie ein Datum im Format 'DD.MM.YYYY' ein."
,
"Datum"
)
Else
strInput = InputBox(
"Bitte geben Sie ein Datum im Format 'DD.MM.YYYY' ein."
& vbCrLf & _
"Versuch: "
& i &
" von "
& MAX_TRY,
"Datum"
)
End
If
If
i = MAX_TRY
Then
Exit
Do
Loop
Until
Not
strInput = vbNullString
And
regEx.test(strInput)
And
IsDate(strInput)
If
Not
strInput = vbNullString
Then
get_date =
CDate
(strInput)
End
If
End
Function