Public Class Form5 Private datecycle1 As Date Private datecycle2 As Date Private heureallumagecycle1 As Integer Private heureeteintcycle1 As Integer Private heureallumagecycle2 As Integer Private heureeteintcycle2 As Integer Private daycycle1 As Integer Private daycycle2 As Integer Private Sub Initialize() datecycle1 = "30/10/2010" daycycle1 = 15 datecycle2 = DateAdd(DateInterval.Day, daycycle1, datecycle1) daycycle2 = 10 heureallumagecycle1 = 16 heureeteintcycle1 = 10 heureallumagecycle2 = 19 heureeteintcycle2 = 7 End Sub Private Function IsEteint() As String Dim hournow As Date Dim item() As String Dim mystr As String Dim expression1 As Boolean Dim expression2 As Boolean hournow = FormatDateTime(Now, DateFormat.ShortTime) mystr = "" item = Split(hournow, ":") 'obtenir seulement la partie heure If (DateDiff(DateInterval.Day, datecycle1, Now) < daycycle1) And (DateDiff(DateInterval.Day, datecycle1, Now) > 0) Then 'je suis dans le cycle 1 expression1 = (CInt(item(0)) >= heureallumagecycle1) And (CInt(item(0)) < 24) expression2 = (CInt(item(0)) >= 0) And (CInt(item(0)) < heureeteintcycle1) If expression1 Or expression2 Then mystr = "cycle1 allumé" Else mystr = "cycle1 éteint" End If End If If (DateDiff(DateInterval.Day, datecycle2, Now) < daycycle2) And (DateDiff(DateInterval.Day, datecycle2, Now) > 0) Then 'je suis dans le cycle 2 expression1 = (CInt(item(0)) >= heureallumagecycle2) And (CInt(item(0)) < 24) expression2 = (CInt(item(0)) >= 0) And (CInt(item(0)) < heureeteintcycle2) If expression1 Or expression2 Then mystr = "cycle2 allumé" Else mystr = "cycle2 éteint" End If End If Return mystr End Function Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Initialize() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = FormatDateTime(Now, DateFormat.ShortTime) Label2.Text = IsEteint() End Sub End Class
'vérification pour savoir si lumiere allumée ou pas If (DateDiff(DateInterval.Day, DateD, Now) < 0) Then If ((txt_Allumage1.Text < Label33.Text) And (txt_Allumage1.Text < Now.Hour And Now.Hour < Label33.Text)) Then F_Accueil.ToolStripStatusLabel1.Text = "allumee" ElseIf ((txt_Allumage1.Text > Label33.Text) And (Now.Hour < Label33.Text Or Now.Hour < 24)) Then F_Accueil.ToolStripStatusLabel1.Text = "allumee" Else F_Accueil.ToolStripStatusLabel1.Text = "eteinte" End If Else If ((txt_Allumage2.Text < Label32.Text) And (txt_Allumage2.Text < Now.Hour And Now.Hour < Label32.Text)) Then F_Accueil.ToolStripStatusLabel1.Text = "allumee" ElseIf ((txt_Allumage2.Text > Label32.Text) And (Now.Hour < Label32.Text Or Now.Hour < 24)) Then F_Accueil.ToolStripStatusLabel1.Text = "allumee" Else F_Accueil.ToolStripStatusLabel1.Text = "eteinte" End If End If