Timer

zhebulonn Messages postés 37 Date d'inscription jeudi 26 décembre 2002 Statut Membre Dernière intervention 6 avril 2007 - 26 juin 2003 à 12:53
zhebulonn Messages postés 37 Date d'inscription jeudi 26 décembre 2002 Statut Membre Dernière intervention 6 avril 2007 - 27 juin 2003 à 10:26
Je voudrais quand appuyant plus d'1/2 seconde sur un bouton, un compteur s'incremente tant qu'on ne relache pas le bouton. Je pense qu'il faut utiliser un timer, mais je n'y suis pas tres famillier et je n'y arrive pas...

zhebulonn

4 réponses

slr Messages postés 75 Date d'inscription mercredi 23 octobre 2002 Statut Membre Dernière intervention 13 juillet 2004
26 juin 2003 à 13:23
Private IsPressed As Boolean
Private tps As Long

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = 1 Then
    IsPressed = True
  End If
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = 1 Then
    IsPressed = False
  End If
End Sub

Private Sub Form_Load()
  Text1.Text = "0"
End Sub

Private Sub Timer1_Timer()
  If IsPressed = False Then
    tps = 0
  ElseIf IsPressed Then
    tps = tps + 1
    If tps > 50 Then Text1.Text = CStr(Format(Text1.Text) + 1)
  End If
End Sub


tu mets ce code dans une feuille quelconque en y plaçant un textbox nommé Text1, un bouton nommé Command1 et un timer nommé Timer1.

;)
slr
0
zhebulonn Messages postés 37 Date d'inscription jeudi 26 décembre 2002 Statut Membre Dernière intervention 6 avril 2007
26 juin 2003 à 14:48
Ca ne marche pas chez moi, il n'y a rien qui se passe quand j'appuie sur le bouton. J'ai bien une textbox, un commandbutton et un timer avec les noms qui vont avec...

zhebulonn
0
slr Messages postés 75 Date d'inscription mercredi 23 octobre 2002 Statut Membre Dernière intervention 13 juillet 2004
26 juin 2003 à 18:23
Excuses-moi, j'ai oublié de te préciser qu'il fallait mettre la propriété "interval" du Timer à 1 ou autre entier positif !
:clown)
slr
0
zhebulonn Messages postés 37 Date d'inscription jeudi 26 décembre 2002 Statut Membre Dernière intervention 6 avril 2007
27 juin 2003 à 10:26
C'est cool, ca marche.
Merci

zhebulonn
0
Rejoignez-nous