Bonjour à tous,
J'ai le besoin de savoir comment je peux faire un chronométreur par un VB code ou par une formule.
ZAX-FR
Bonjour à tous,
J'ai le besoin de savoir comment je peux faire un chronométreur par un VB code ou par une formule.
ZAX-FR
Salut, démarche à suivre :
• Créer un UserForm
• un Label LblTemps qui visualisera le chrono au format hh:mm:ss
• 3 Boutons : BtnStart BtnStop BtnRaz
Dans UserForm
Dans module standard baptisé mTimer
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Option Explicit Private Sub BtnRaz_Click() TimerOff LblTemps.Caption = "00:00:00" BtnStart.Enabled = True BtnStop.Enabled = False End Sub Private Sub BtnStart_Click() TimerOn 1000 BtnStart.Enabled = False BtnStop.Enabled = True End Sub Private Sub BtnStop_Click() BtnStart.Enabled = True BtnStop.Enabled = False TimerOff End Sub Private Sub UserForm_Initialize() LblTemps.Caption = "00:00:00" BtnStart.Enabled = True BtnStop.Enabled = False End Sub Private Sub UserForm_Terminate() TimerOff Unload Me End Sub
Dans feuil1
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 Private Declare Function SetTimer Lib "User32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long Private Declare Function KillTimer Lib "User32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long Option Explicit Dim TimerID As Long Private Sub Chrono() Dim Temps As Double Temps = TimeValue(UserForm1.LblTemps.Caption) + TimeSerial(0, 0, 1) UserForm1.LblTemps.Caption = Format(Temps, "hh:mm:ss") End Sub Sub TimerOff() KillTimer 0, TimerID End Sub Sub TimerOn(Interval As Long) TimerID = SetTimer(0, 0, Interval, AddressOf Chrono) End Sub
Affectuer un bouton à Bouton1_QuandClic
Une autre Version :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Option Explicit Sub Bouton1_QuandClic() UserForm1.Show vbModeless End Sub
• Créer un UserForm
• un Label LblTemps qui visualisera le chrono au format hh:mm:ss
• 1 Bouton : BtnRaz
• 1 ToggleButton : TButton1
Dans UserForm
Pour la suite mTimer et Bouton comme précédemment.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Option Explicit Private Sub BtnRaz_Click() TimerOff LblTemps.Caption = "00:00:00" With TButton1 .Caption = "Start" .ForeColor = &H8000& .Value = False End With End Sub Private Sub TButton1_Click() With TButton1 If .Value = True Then .Caption = "Stop" .ForeColor = &H80& TimerOn 1000 Else .Caption = "Start" .ForeColor = &H8000& TimerOff End If End With End Sub Private Sub UserForm_Initialize() With TButton1 .Caption = "Start" .ForeColor = &H8000& .Value = False End With End Sub Private Sub UserForm_Terminate() TimerOff Unload Me End Sub
Bonjour,
Je vous remercie, Vos codes marchent tres bien.
Je voudrai questionner vous un autre question, j'ai basoin d'ajouter
des caracteres comme "eَ " dans mon reponse, comment je peux les ajouter ?
ZAX-FR
Partager