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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Affichage(Text1.Text)
End Sub
Private Sub Affichage(ByVal 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 = CDate(DateSoumise) 'conversion d'un littéral 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 vérifier/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.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label2.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label3.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label4.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label5.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label6.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label7.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label8.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label9.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label10.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label11.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label12.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label13.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label14.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label15.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label16.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label17.Text = TheDate
TheDate = RecupMardiSuivant(TheDate, U)
Label18.Text = TheDate
End Sub
Function RecupMardiSuivant(ByVal dateEnCours As Date, ByVal NumMardi As Integer) 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(ByVal DateSoumis As Date) As Integer
Day = Microsoft.VisualBasic.Left(DateSoumis, 2)
End Function
Function Month(ByVal DateSoumis As Date) As Integer
Month = Mid(DateSoumis, 4, 2)
End Function
Function Year(ByVal DateSoumis As Date) As Integer
Year = Microsoft.VisualBasic.Right(DateSoumis, 4)
End Function
'******************** fin fonctions récupération jour,mois,année *************************
End Class |
Partager