Programmation Msgbox si Caption = X

napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   -  
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour, j'aurais voulu avoir votre aide pour cette commande.

Je n'arrive pas a faire en sorte que qu'une fenêtre s'ouvre si les 3 premiers boutons sont cochés.
J'ai 3 buttons et 2 CheckBox
Si je coche la première CheckBox cela va me mettre un X sur le ou les boutons que je clic
Et je veux qu'une fois avoir cliquer sur les 3 boutons donc rempli de X j'ai une fenetre qu'il souvre



If bt1.Caption = "X" And bt2.Caption = "X" And bt3.Caption = "X" Then MsgBox "X Gagne"
La sa ne met rien mais la fenetre ne s'ouvre pas


La sa met une erreur
If bt1.valeur = Check1.Text And bt2.valeur = Check1.Text Then MsgBox "ok"

Concretement je veux dire:
If les 3 boutons ont pour caption "X" alors mettre fenetre.

Merci
A voir également:

49 réponses

napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
a
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
et a part par honomatopé... c'est un oui??
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Oui en plein de ligne je t'ai envoyer un MP ;)
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
ok, j ai vu ton code...

bon, normal.. un copier coller 9 fois sur chaque boutons.. classique :)

2 choses qui rendront ton code beaucoup plus simple.. l'indexage des boutons et enlever tes coches

apres on verra comment lui faire trouver si "X" ou "O" sont alignés, pour ca tu va pleurer un peu pour comprendre, mais c'est normal et t'en trouvera beaucoup plus.. comment dire.. ravi :)

donc l'indexage des boutons cf post 16

https://forums.commentcamarche.net/forum/affich-13554873-programmation-msgbox-si-caption-x#16

dis moi si tu as tout compris :)
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Oui j'ai compris le system
mais tu n'aurais pas un bout de code comme exemple
En gros tu ne travaille en quelque sorte le code que dans "1" boutton en présisent () les bouttons souhaités
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
cré un bouton (nommé Command1), copie le, dis ok pour index et colle ca dedans :

Private Sub Command1_Click(Index As Integer)
MsgBox "vous avez appuer sur le bouton d'index " & Index
End Sub
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Ouais je comprend le system mais par exemple la pour le morpion je dois faire
J'ai 9 bouttons indexés

Private Sub Command1_Click(Index As Integer)
If Check1.Value = 1 Then Caption = "X"
If Check2.Value = 1 Then Caption = "O"
End Sub

avant le caption fo bien ke je mete
Command1(1)
Command1(2)
Command1(3)
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
J'ai trouver il fallait rajouter une autre condition sa donnerait sa a peut pres ?

Private Sub Command1_Click(Index As Integer)
If Check1.Value = 1 And Command1(1).Value = True Then Command1(1).Caption = "X"
If Check2.Value = 1 And Command1(1).Value = True Then Command1(1).Caption = "O"

If Check1.Value = 1 And Command1(2).Value = True Then Command1(2).Caption = "X"
If Check2.Value = 1 And Command1(2).Value = True Then Command1(2).Caption = "O"

If Check1.Value = 1 And Command1(3).Value = True Then Command1(3).Caption = "X"
If Check2.Value = 1 And Command1(3).Value = True Then Command1(3).Caption = "O"

If Check1.Value = 1 And Command1(4).Value = True Then Command1(4).Caption = "X"
If Check2.Value = 1 And Command1(4).Value = True Then Command1(4).Caption = "O"

If Check1.Value = 1 And Command1(5).Value = True Then Command1(5).Caption = "X"
If Check2.Value = 1 And Command1(5).Value = True Then Command1(5).Caption = "O"

If Check1.Value = 1 And Command1(6).Value = True Then Command1(6).Caption = "X"
If Check2.Value = 1 And Command1(6).Value = True Then Command1(6).Caption = "O"

If Check1.Value = 1 And Command1(7).Value = True Then Command1(7).Caption = "X"
If Check2.Value = 1 And Command1(7).Value = True Then Command1(7).Caption = "O"

If Check1.Value = 1 And Command1(8).Value = True Then Command1(8).Caption = "X"
If Check2.Value = 1 And Command1(8).Value = True Then Command1(8).Caption = "O"

If Check1.Value = 1 And Command1(9).Value = True Then Command1(9).Caption = "X"
If Check2.Value = 1 And Command1(9).Value = True Then Command1(9).Caption = "O"
End Sub
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
et ca c'est pas mieux ?

If Check1.Value = 1 Then Command1(index).Caption = "X"
If Check2.Value = 1 Then Command1(index).Caption = "O"


:D

?
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Ahhhhh tu m'énerve t trop fort mdrrrrr
Bon j'ai essayer de le faire avant de lire ta réponce donc je te donne quand meme sa ^^


Private Sub btReset_Click()

End Sub

Private Sub Command1_Click(Index As Integer)
If Check1.Value = 1 And Command1(1).Value = True Then Command1(1).Caption = "X"
If Check2.Value = 1 And Command1(1).Value = True Then Command1(1).Caption = "O"

If Check1.Value = 1 And Command1(2).Value = True Then Command1(2).Caption = "X"
If Check2.Value = 1 And Command1(2).Value = True Then Command1(2).Caption = "O"

If Check1.Value = 1 And Command1(3).Value = True Then Command1(3).Caption = "X"
If Check2.Value = 1 And Command1(3).Value = True Then Command1(3).Caption = "O"

If Check1.Value = 1 And Command1(4).Value = True Then Command1(4).Caption = "X"
If Check2.Value = 1 And Command1(4).Value = True Then Command1(4).Caption = "O"

If Check1.Value = 1 And Command1(5).Value = True Then Command1(5).Caption = "X"
If Check2.Value = 1 And Command1(5).Value = True Then Command1(5).Caption = "O"

If Check1.Value = 1 And Command1(6).Value = True Then Command1(6).Caption = "X"
If Check2.Value = 1 And Command1(6).Value = True Then Command1(6).Caption = "O"

If Check1.Value = 1 And Command1(7).Value = True Then Command1(7).Caption = "X"
If Check2.Value = 1 And Command1(7).Value = True Then Command1(7).Caption = "O"

If Check1.Value = 1 And Command1(8).Value = True Then Command1(8).Caption = "X"
If Check2.Value = 1 And Command1(8).Value = True Then Command1(8).Caption = "O"

If Check1.Value = 1 And Command1(9).Value = True Then Command1(9).Caption = "X"
If Check2.Value = 1 And Command1(9).Value = True Then Command1(9).Caption = "O"




If Command1(1).Caption = "X" And Command1(2).Caption = "X" And Command1(3).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(4).Caption = "X" And Command1(5).Caption = "X" And Command1(6).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(7).Caption = "X" And Command1(8).Caption = "X" And Command1(9).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(1).Caption = "X" And Command1(4).Caption = "X" And Command1(7).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(2).Caption = "X" And Command1(5).Caption = "X" And Command1(8).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(3).Caption = "X" And Command1(6).Caption = "X" And Command1(9).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(1).Caption = "X" And Command1(5).Caption = "X" And Command1(9).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(1).Caption = "O" And Command1(2).Caption = "O" And Command1(3).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(4).Caption = "O" And Command1(5).Caption = "O" And Command1(6).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(7).Caption = "O" And Command1(8).Caption = "O" And Command1(9).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(1).Caption = "O" And Command1(4).Caption = "O" And Command1(7).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(2).Caption = "O" And Command1(5).Caption = "O" And Command1(8).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(3).Caption = "O" And Command1(6).Caption = "O" And Command1(9).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(1).Caption = "O" And Command1(5).Caption = "O" And Command1(9).Caption = "O" Then
MsgBox "O Gagne"
End If
End Sub
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
là est tout l interet de l'index... c'est de se référencer au numéro du bouton tout en ayant le meme code pour tous les boutons ;)
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Ce qui nous donne ^^

Private Sub Command1_Click(Index As Integer)
If Check1.Value = 1 Then Command1(Index).Caption = "X"
If Check2.Value = 1 Then Command1(Index).Caption = "O"

If Command1(1).Caption = "X" And Command1(2).Caption = "X" And Command1(3).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(4).Caption = "X" And Command1(5).Caption = "X" And Command1(6).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(7).Caption = "X" And Command1(8).Caption = "X" And Command1(9).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(1).Caption = "X" And Command1(4).Caption = "X" And Command1(7).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(2).Caption = "X" And Command1(5).Caption = "X" And Command1(8).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(3).Caption = "X" And Command1(6).Caption = "X" And Command1(9).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(1).Caption = "X" And Command1(5).Caption = "X" And Command1(9).Caption = "X" Then
MsgBox "X Gagne"
End If
If Command1(1).Caption = "O" And Command1(2).Caption = "O" And Command1(3).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(4).Caption = "O" And Command1(5).Caption = "O" And Command1(6).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(7).Caption = "O" And Command1(8).Caption = "O" And Command1(9).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(1).Caption = "O" And Command1(4).Caption = "O" And Command1(7).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(2).Caption = "O" And Command1(5).Caption = "O" And Command1(8).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(3).Caption = "O" And Command1(6).Caption = "O" And Command1(9).Caption = "O" Then
MsgBox "O Gagne"
End If
If Command1(1).Caption = "O" And Command1(5).Caption = "O" And Command1(9).Caption = "O" Then
MsgBox "O Gagne"
End If
End Sub
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
bon.. maintenant on va s'attaquer à ton X ou O...

1) on n'utilise plus ta coche.. si "X" vient de jouer, ca sera forcement le tour de "O" et inversement... jusque là tu me suis..

donc on cré une variable générale CarEnCours :

dans général déclaration (c'est a dire en premire ligne de code, avant toutes les sub :

Dim CarEnCours

on l initialise dans Form_Load avec CarEnCours ="X"

Pour que le bouton prenne la marque voulu on a dans command_click :

If BtJeu(Index).Caption <> "" Then Exit Sub 'ceci si il clique sur un bouton ayant dejà une marque

BtJeu(Index).Caption = CarEnCours 'pour mettre "X" ou "O"

et pour faire l inversion dans ton command1_click(Index as integer) à la fin, juste avant le end sub, ajoute ceci:

If CarEnCours = "X" Then CarEnCours = "O" Else CarEnCours = "X"
end sub

je le met à la fin, car c'est une fois que lon aura verifier si le joueur à gané qu'il faut changer de signe..
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Alors attend que je comprenne bien ce que je fais

Dim CarEnCours
Dim sa veut dire quoi concrètement on demande quoi au programme sa cré une variable c'est sa ?

on l initialise dans Form_Load avec CarEnCours ="X"
La sa va faire quoi au juste ?
Form c'est la fenetre ?

If Command1(Index).Caption <> ""
<> c'est quoi ? ni plus grand ni plus petit que " " ?

Dsl c'est juste pour bien tout maitriser sur sa et pouvoir le réutiliser quand j'en aurais besoin sur d'autre trucs par exemple :)
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
Dim sert à déclarer une variable

Form_Load avec CarEnCours ="X"
=> Form load est une des premiere instruction appelé au démarage du programme. litéralement au chargement de la feuille

If Command1(Index).Caption <> ""

<> veut dire différent en vb
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Ok merci j'ai compris encore quelques questions :p dsl
If Command1(Index).Caption <> "" Then Exit Sub
La je vois pas trop
si la caption des bouttons est différent de rien donc qu'il y a deja x ou o alors
exit sub ?
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
ben si y a deja un "X" ou "O".. l'utilisateur joue sur une case deja utilisée.. donc ne joue pas.. d où le exit sub
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Lol ouais j'ai bien compris ^^ mais exit sub sa veut dire que sa annule la commande c'est sa ?
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
ca veut dire qu il quitte la sub en cours.. comme s'il allait directyement au en sub de la fin du command_click
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Okok et j'ai encore un ptit soucis niveau code :p

Le match nul je pensais faire un truc comme sa :

If Command1(Index).Caption <> "" And Command1(Index).Value = True Then MsgBox "Match Nul"
Genre si toutes les cases sont cochées et que leurs caption est forcément différent de "" alors mettre une msgbox je ne sais pas si c'est possible
0
jjsteing Messages postés 1670 Date d'inscription   Statut Contributeur Dernière intervention   181
 
non, pas exactement.. mais ton resonnement est bon...

Le hic je pense que tu n a pas compris l'indexage...

index dans command(index) correspond au bouton que le joueur à cliquer.. et non tous les boutons
0
napster94700 Messages postés 76 Date d'inscription   Statut Membre Dernière intervention   16
 
Ah ok !!!

Donc
If Command1(1).Caption <> "" And Command1(2).Caption <> "" And Command1(3).Caption <> "" And Command1(4).Caption <> "" And Command1(5).Caption <> "" And Command1(6).Caption <> "" And Command1(7).Caption <> "" And Command1(8).Caption <> "" And Command1(9).Caption <> "" Then
MsgBox "Match Nul"
0