Trois clics Trois captions (CommandButton)

Staple1600

XLDnaute Barbatruc
Bonjour à tous

Voila le problème:
Affecter une valeur différente à CommandButton
selon clic

1clic=1, 2clic=2, 3clic=3 enusite on revient à 1 et ainsi de suite


Voila ou j'en suis
Private Sub CommandButton1_Click()
z = CommandButton1.Caption
Select Case z
Case 1
CommandButton1.Caption = 2
Case 2
CommandButton1.Caption = 3
Case 3
CommandButton1.Caption = 1
End Select
End Sub
Private Sub UserForm_Initialize()
CommandButton1.Caption = 1
End Sub
Ca ne fonctionne pas
 
Solution
Merci Hervé

Effectivement
Private Sub CommandButton1_Click()
n = n + 1
If n > 3 Then n = 1
Select Case n
Case 1: CommandButton1.Caption = 'VU'
Case 2: CommandButton1.Caption = 'A VOIR'
Case 3: CommandButton1.Caption = 'N/R'
End Select
End Sub
Private Sub UserForm_Initialize()
CommandButton1.Caption = 'A'
End Sub

Mais je comprends pas pourquoi
parfois il faut cliquer deux fois de suite
pour obtenir le changement de valeur

Hervé

XLDnaute Barbatruc
Bonjour staple, le forum

:)

essaye comme ceci :

Private Sub CommandButton1_Click()
n = n + 1
If n > 3 Then n = 1
CommandButton1.Caption = n
End Sub

en déclarant public la variable n dans un module standard (public n as byte)

salut
 

Staple1600

XLDnaute Barbatruc
Merci cela fonctionne

Et si on veut remplacer par des lettres?

exemple:
1) clic = VU
2) clic = A VOIR
3) clic= N/R

J'ai pensé à pour (ABC)
x = 65
n = Chr(x) + 1
If n > Chr(67) Then n = Chr(65)
CommandButton1.Caption = n

mais ca ne fonctionne pas
 

Hervé

XLDnaute Barbatruc
re

:)

Alors repart avec le systeme du selct case :

Private Sub CommandButton1_Click()
n = n + 1
If n > 3 Then n = 1
Select Case n
Case 1: CommandButton1.Caption = 'VU'
Case 2: CommandButton1.Caption = 'A VOIR'
Case 3: CommandButton1.Caption = 'N/R'

End Sub

salut
 

Staple1600

XLDnaute Barbatruc
Merci Hervé

Effectivement
Private Sub CommandButton1_Click()
n = n + 1
If n > 3 Then n = 1
Select Case n
Case 1: CommandButton1.Caption = 'VU'
Case 2: CommandButton1.Caption = 'A VOIR'
Case 3: CommandButton1.Caption = 'N/R'
End Select
End Sub
Private Sub UserForm_Initialize()
CommandButton1.Caption = 'A'
End Sub

Mais je comprends pas pourquoi
parfois il faut cliquer deux fois de suite
pour obtenir le changement de valeur
 

Discussions similaires

Réponses
3
Affichages
347

Statistiques des forums

Discussions
312 480
Messages
2 088 757
Membres
103 950
dernier inscrit
Thomas Solioz