1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| Option Explicit
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
Affichage Text1.Text
End If
End Sub
Private Sub Command1_Click()
Affichage Text1.Text
End Sub
Private Sub Affichage(DateSoumise As String)
Dim UneDate As Date, TheDate As Date, TheDateFin As Date, T As Integer, U As Integer
'vérification de l'entrée utilisateur
If Not IsDate(DateSoumise) Then
MsgBox "votre entrée n'est pas une date valide", vbInformation, "erreur"
Exit Sub
End If
UneDate = CVDate(DateSoumise) 'conversion d'un literal en type Date
If Weekday(UneDate) <> vbTuesday Then
MsgBox "le jour de votre entrée n'est pas un mardi", vbInformation, "erreur"
Exit Sub
End If
TheDate = "01/" & Month(UneDate) & "/" & Year(UneDate) '1er jour du mois proposé
'pour verifier/compter si le mois contient plus de 4 mardi
TheDateFin = DateAdd("m", 1, TheDate) ' ajoute 1 mois au mois proposé
TheDateFin = DateAdd("d", -1, TheDateFin) ' enlevé 1 jour pour avoir le dernier jour du mois proposé
'compte le nombre de mardi du mois proposé
For T = 0 To Day(TheDateFin)
If Weekday(DateAdd("d", T, TheDate)) = vbTuesday Then ' cette date est un mardi
U = U + 1 'incrémente les mardis
If U < 5 And DateAdd("d", T, TheDate) = UneDate Then Exit For
If U = 5 And DateAdd("d", T, TheDate) = UneDate Then
U = 1 'pour récupérer le 1er mardi du mois du mois suivant
TheDate = RecupMardiSuivant(TheDate, U)
Exit For
End If
End If
Next T
TheDate = RecupMardiSuivant(TheDate, U)
Label1.Caption = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label2.Caption = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label3.Caption = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label4.Caption = TheDate
End Sub
Function RecupMardiSuivant(dateEnCours As Date, NumMardi) As Date
Dim DateDeb As Date, DateFin As Date, T As Integer, U As Integer
DateDeb = "01/" & Month(dateEnCours) & "/" & Year(dateEnCours)
DateDeb = DateAdd("m", 1, DateDeb) ' début du mois suivant
DateFin = DateAdd("m", 1, DateDeb)
DateFin = DateAdd("d", -1, DateFin) ' fin du mois suivant
For T = 0 To Day(DateFin)
If Weekday(DateAdd("d", T, DateDeb)) = vbTuesday Then
U = U + 1
If U = NumMardi Then
RecupMardiSuivant = DateAdd("d", T, DateDeb)
Exit For
End If
End If
Next
End Function
'************************ fonctions récupération jour,mois,année *************************
Function Day(DateSoumis As Date) As Integer
Day = Left(DateSoumis, 2)
End Function
Function Month(DateSoumis As Date) As Integer
Month = Mid(DateSoumis, 4, 2)
End Function
Function Year(DateSoumis As Date) As Integer
Year = Right(DateSoumis, 4)
End Function
'******************** fin fonctions récupération jour,mois,année ************************* |
Partager