Sub EssaiCascadeUF()
UF_1.Show
UF_2.Show
End Sub
Private Sub UserForm_activate()
TimeDebut = Timer
DoEvents
While Timer < TimeDebut + 4
Wend
Unload Me
End Sub
Option Explicit
Private TPlanifications() As Planification, Idt As Long
Rem. En principe vous ne devriez pas avoir besoin de cette procédure, qui désactive tous les objets Planification.
Public Sub DéplanifierTout()
Dim P As Long, M As Long
On Error Resume Next: M = UBound(TPlanifications): If Err Then Exit Sub
On Error GoTo 0
For P = 1 To M: Idt = Idt Mod M + 1
If Not TPlanifications(Idt) Is Nothing Then TPlanifications(Idt).Annuler
Set TPlanifications(Idt) = Nothing: Next P
End Sub
Rem. Ne pas utiliser ces autres procédures: elles sont à l'usage exclusif des objets Planification.
Public Function IdtPlanificationLancée(ByVal Source As Planification) As Long
Dim P As Long, M As Long
On Error Resume Next: M = UBound(TPlanifications): If Err Then ReDim TPlanifications(1 To 1): M = 1
On Error GoTo 0
For P = 1 To M: Idt = Idt Mod M + 1: If TPlanifications(Idt) Is Nothing Then Exit For
Next P: If P > M Then ReDim Preserve TPlanifications(1 To P): Idt = P
Set TPlanifications(Idt) = Source
Application.OnTime Source.HeureOT, "'MPlanificateur.OnTimeJoue " & Idt & "'"
IdtPlanificationLancée = Idt
End Function
Public Sub AnnulerPlanification(ByVal Idt As Long)
On Error Resume Next
Application.OnTime TPlanifications(Idt).HeureOT, "'MPlanificateur.OnTimeJoue " & Idt & "'", Schedule:=False
Set TPlanifications(Idt) = Nothing
End Sub
Private Sub OnTimeJoue(ByVal Idt As Long)
On Error Resume Next
TPlanifications(Idt).MéthodeRéservéeÀOnTimeJoue
Set TPlanifications(Idt) = Nothing
End Sub
Rem. Cette classe permet d'exploiter un Application.Ontime dans des objets, via un évènement Échoit.
Option Explicit
Event Échoit() ' Évènement. Se produit à l'échéance du délai.
Private HOT As Date, Idt As Long
Public Sub PlanifierDans(ByVal Délai)
Rem. ——— Méthode. Planifie l'évènement Échoit dans un délai indiquée. Annule une éventuelle planification préalable.
' Délai: Expression String de la forme "hh:mm:ss" ou bien un nombre de secondes.
If Engagé Then MPlanificateur.AnnulerPlanification Idt
If VarType(Délai) = vbString Then HOT = Now + TimeValue(Délai) Else HOT = Now + TimeSerial(0, 0, Délai)
Idt = MPlanificateur.IdtPlanificationLancée(Me)
End Sub
Public Sub Annuler()
Rem. ——— Méthode. Annule la dernière planification s'il en existe une.
If Idt > 0 Then MPlanificateur.AnnulerPlanification Idt: Idt = 0
End Sub
Public Function HeureOT() As Date
Rem. ——— Propriété en lecture seule. Dernière heure de planification.
HeureOT = HOT
End Function
Public Function Engagé() As Boolean
Rem. —— Propriété en lecture seule. Condition planification lancée.
Engagé = Idt > 0: End Function
'
Public Sub MéthodeRéservéeÀOnTimeJoue() ' NE PAS UTILISER.
Idt = 0: RaiseEvent Échoit
End Sub