Un poco tarde...
aquí está la mía:
Option Explicit
Private Const sMonths$ = "01 02 03 04 05 06 07 08 09 10 11 12"
Private Const s31Months$ = " 1 3 5 7 8 01 03 05 08 10 12 "
Private Const sDays$ = sMonths & " 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31"
'// Acepta formatos: DD/MM/YYYY, D/MM/YYYY y DD/M/YYYY.
Public Static Function IsDate_Psyke1(ByRef sDate$) As Boolean
Dim sDay$, sMonth$, sYear$, lp1&, lp2&
If LenB(sDate) < &H16 And LenB(sDate) > &HE Then
lp1 = InStrB(1, sDate, "/", vbBinaryCompare)
If lp1 = 0 Then Exit Function
sDay = LeftB$(sDate, lp1 - 1)
If InStrB(1, sDays, sDay, vbBinaryCompare) Then
lp2 = InStrB(lp1 + 1, sDate, "/", vbBinaryCompare)
If lp2 = 0 Then Exit Function
sMonth = MidB$(sDate, lp1 + 2, lp2 - lp1 - 2)
If InStrB(1, sMonths, sMonth, vbBinaryCompare) Then
sYear = RightB$(sDate, 8)
If Not (sYear Like "####") Then Exit Function
If InStrB(1, "02", sMonth, vbBinaryCompare) Then
If InStrB(1, "29", sDay, vbBinaryCompare) Then
IsDate_Psyke1 = ((sYear Mod &H4 = 0) And (sYear Mod &H64) Or (sYear Mod &H190 = 0))
Exit Function
ElseIf InStrB(1, "30", sDay, vbBinaryCompare) Then
Exit Function
End If
ElseIf InStrB(1, "31", sDay, vbBinaryCompare) Then
IsDate_Psyke1 = InstrB(1, s31Months, sMonth, vbBinaryCompare)
Exit Function
End If
IsDate_Psyke1 = True
End If
End If
End If
End Function
Tests:
Private Sub Form_Load()
Const sLine$ = "----------------------------------------"
Debug.Print sLine; "TRUE"; sLine
Debug.Print IsDate_Psyke1("31/07/2000")
Debug.Print IsDate_Psyke1("29/02/2004")
Debug.Print IsDate_Psyke1("15/07/2000")
Debug.Print IsDate_Psyke1("30/12/2011")
Debug.Print sLine; "FALSE"; sLine
Debug.Print IsDate_Psyke1("29/02/2003")
Debug.Print IsDate_Psyke1("01/13/2011")
Debug.Print IsDate_Psyke1("30/02/2001")
Debug.Print IsDate_Psyke1("00/12/2011")
Debug.Print IsDate_Psyke1("as/12/2000")
Debug.Print IsDate_Psyke1("13/as/2000")
Debug.Print IsDate_Psyke1("-31/44/2070")
Debug.Print IsDate_Psyke1("31/12/20s0")
End Sub
Resultado:
----------------------------------------TRUE----------------------------------------
True
True
True
True
----------------------------------------FALSE----------------------------------------
False
False
False
False
False
False
False
False
Ahora con el proyecto de
raul338 (compilado y con la función de BlackZeroX actualizada), los tests me dicen que devuelve resultados correctos, y en cuanto a velocidad me dio esto:
Testeo de velocidades
==============================
43,920 msec Ignorante v1.1
35,993 msec 79137913
21,728 msec BlackZeroX
73,901 msec $Edu$
89,051 msec Tenient101
27,381 msec Raul338
16,374 msec Psyke1
@Raul338, @Ignorante :
Debug.Print IsDate_r338("31/12/20f0") ' = True.. xD
Debug.Print heyIgnorante_isDate("31/12/25y0") ' = True.. xD
Por tanto las funciones que dan resultados correctos:
Testeo de velocidades
==============================
35,993 msec 79137913
21,728 msec BlackZeroX
16,374 msec Psyke1
@BlackZeroX:
Me gustaría que me explicaras un par de cosas de tu código, si te pillo por el msn te molesto, que hace mucho que no hablamos.
DoEvents!