Je me suis souvent demandé quel type de ligne de code on obtenait quand on payait un consultant à 205€ de l'heure. Je pensais que ce ne serait pas un code incroyable . Mais maintenant que j'ai effectivement vu (merci Will Nesbitt) le code produit par un consultant à 2000€ d'IBM, je peux dire que c'est effectivement grandiose... mais pas dans le sens que je l'espérais.

'checks if a date is valid
Private Function validDate ( dateString As String ) As Integer
Dim theDay As String
Dim theMonth As String
Dim theYear As String
Dim separator As String

Dim dayNumber As Integer
Dim monthNumber As Integer
Dim yearNumber As Integer

Dim currentYear As Integer

Dim remainder As Integer

'calculate the current year to check the date is not in the future
currentYear = Year ( Now ( ) )

'a blank date is considered valid as it is not a mandatory field
If Len ( dateString ) = 0 Then
validDate = True
Exit Function
End If

'dates of the form dd/mm/yyyy are 10 characters long including the slash (/)
If Len ( dateString ) >< 10 Then
validDate = False
Exit Function
End If

Stop
'check the seperators are correct
Dim i As Integer

For i = 3 To 6
separator = Mid ( dateString, i, 1 )

If Not ( separator = "/" Or separator = "-" Or separator = "." ) Then
validDate = False
Exit Function
End If
i = i + 2
Next

'extract the parts of the date string
theDay = Mid ( dateString, 1, 2 )
theMonth = Mid ( dateString, 4, 2)
theYear = Mid ( dateString, 7, 4 )

If theYear = "" Then
validDate = False
Exit Function
End If

If theDay = "" Then
validDate = False
Exit Function
Else
dayNumber = Cint ( theDay )
End If

If theMonth = "" Then
validDate = False
Exit Function
Else
monthNumber = Cint ( theMonth )
End If

'9 4 6 11
Select Case monthNumber
'the month is either April, June, September or November i.e. 30 days
Case 4,6,9,11:
If dayNumber >0 And dayNumber <= 30 Then
validDate = True
Exit Function
Else
validDate = False
Exit Function
End If

'the month is february, check for leap year
Case 2 :
remainder = yearNumber Mod 4

'The year is not a leap year so the day number must be 1 - 28
If remainder >< 0 Then
If dayNumber > 0 And dayNumber <= 28 Then
validDate = True
Exit Function
End If
Else
If dayNumber > 0 And dayNumber <=29 Then
validDate = True
Exit Function
Else
validDate = False
Exit Function
End If
End If

'the month is not february or a month with 30 days
Case Else :
If dayNumber > 0 And dayNumber <= 31 Then
validDate = True
Exit Function
Else
validDate = False
Exit Function
End If
End Select
End Function

 

Comme quoi, en y regardant de plus près ,la donation de 50 Million de $ à la fondation Apache ne m'impressionne plus trop...