IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Comment Faire Un Chronomètre?


Sujet :

Macros et VBA Excel

  1. #1
    Candidat au Club
    Inscrit en
    Juillet 2012
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Juillet 2012
    Messages : 4
    Points : 4
    Points
    4
    Par défaut Comment Faire Un Chronomètre?
    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

  2. #2
    Expert éminent sénior
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Points : 11 274
    Points
    11 274
    Par défaut
    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
    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 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
    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
    Dans feuil1
    Affectuer un bouton à Bouton1_QuandClic
    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
    Une autre Version :
    • Créer un UserForm
    • un Label LblTemps qui visualisera le chrono au format hh:mm:ss
    • 1 Bouton : BtnRaz
    • 1 ToggleButton : TButton1

    Dans UserForm
    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
    Pour la suite mTimer et Bouton comme précédemment.

  3. #3
    Candidat au Club
    Inscrit en
    Juillet 2012
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Juillet 2012
    Messages : 4
    Points : 4
    Points
    4
    Par défaut
    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

Discussions similaires

  1. [LabVIEW 8.5][Débutant] Comment faire un chronomètre ?
    Par geoffrey.ru dans le forum LabVIEW
    Réponses: 2
    Dernier message: 08/09/2011, 17h31
  2. Comment faire un chronomètre ?
    Par adn013 dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 16/08/2007, 16h52
  3. Comment faire un chronomètre en Delphi ou ASM ?
    Par PoOky dans le forum Langage
    Réponses: 8
    Dernier message: 15/06/2005, 20h49
  4. Comment faire pour mettre l'ecran en veille ?
    Par March' dans le forum MFC
    Réponses: 6
    Dernier message: 29/08/2002, 14h25
  5. Comment faire pour créer un bitmap
    Par GliGli dans le forum C++Builder
    Réponses: 2
    Dernier message: 24/04/2002, 15h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo