niakwel
Messages postés16Date d'inscriptionmardi 5 août 2008StatutMembreDernière intervention22 mars 2009
-
21 mars 2009 à 19:22
niakwel
Messages postés16Date d'inscriptionmardi 5 août 2008StatutMembreDernière intervention22 mars 2009
-
22 mars 2009 à 00:02
je suis néophyte en vb, je fais un jeu de memory pour un projet de bts,
pour placer les cartes de façon aléatoire de voudrais faire une boucle qui place les picture box de façon aléatoire
j'ai donc une boucle
For i = 1 To 16
picturebox(i)
End If
Next i
je voudrais donc avoir picturebox1, picturebox2, picturebox3...
jmf0
Messages postés1566Date d'inscriptionmardi 26 décembre 2000StatutMembreDernière intervention 5 avril 20138 21 mars 2009 à 20:22
> une recherche sur ce forum te permettra de trouver une réponse à cette question plus que récurrente !:
2) ton end if sans if est plus que surprenant dans :
For i = 1 To 16
picturebox(i)
End If
Next i
sans parler du reste (que ferait donc un picturebox(i) sans rien d'autre ????)
niakwel
Messages postés16Date d'inscriptionmardi 5 août 2008StatutMembreDernière intervention22 mars 2009 21 mars 2009 à 20:37
c'était juste une partie de l'exemple, la boucle entière donnerait :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Placement As New Random
Dim CarteTiree As Integer
Dim i As Integer
TextBox1.Text = Score
Randomize()
For i = 1 To 16
CarteTiree = Placement.Next(16)
If i = 1 Then
picturebox(CarteTiree).location=10,20
End If
if i=2 then
picturebox(CarteTiree).location=10,20
Next i
Vala vala je vais regarder un peu le groupe de contrôle indexé, merci de ta réponse
jmf0
Messages postés1566Date d'inscriptionmardi 26 décembre 2000StatutMembreDernière intervention 5 avril 20138 21 mars 2009 à 21:37
Ah !
Tu croiis que c'est mieuix, ainsi exposé ???Si (cette fois-ci) ton code est "complet", on ne pourra que s'interroger sur tes deux conditions (si i 1 ou si i 2) puisque, dans un cas comme dans l'autre, on exécute une instruction rigoureusement identique :
picturebox(CarteTiree).location=10,20
!!!
Et j'espère pour toi que ton code montré n'est toujours pas complet, car ton second If n'est pas "fermé" par un End If !
Et si tu commençais à t'appliquer un peu, au moins pour copier-coller ton code sur ce forum ?
Ce serait bien et un peu moins "zazou" ...
Vous n’avez pas trouvé la réponse que vous recherchez ?
niakwel
Messages postés16Date d'inscriptionmardi 5 août 2008StatutMembreDernière intervention22 mars 2009 21 mars 2009 à 22:22
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Placement As New Random
Dim CarteTiree As Integer
Dim i As Integer
TextBox1.Text = Score
Randomize()
For i = 1 To 16
CarteTiree = Placement.Next(16)
If i = 1 Then
picturebox(CarteTiree
).location=15,20
End If
if i=2 then
picturebox(CarteTiree
).location=92,20
end if
If i = 3 Then
picturebox(CarteTiree
).location=169,20
End If
If i = 4 Then
picturebox(CarteTiree
).location=246,20
End If
If i = 5 Then
picturebox(CarteTiree
).location=15,95
End If
If i = 6 Then
picturebox(CarteTiree
).location=
92,95
End If
If i = 7 Then
picturebox(CarteTiree
).location=
169
,95
End If
If i = 8 Then
picturebox(CarteTiree
).location=246,95
End If
If i = 9 Then
picturebox(CarteTiree
).location=15,170
End If
if i=10 then
niakwel
Messages postés16Date d'inscriptionmardi 5 août 2008StatutMembreDernière intervention22 mars 2009 21 mars 2009 à 23:20
Ok Renfiled, j'ai donc revu mon code, j'ai créé un tableau ou je mets les coordonnées des différentes cartes et je vais initialiser chacune des PictureBox grace à ça, j'ai maintenant un autre problème : quand j'essaye de modifier la propriété location.x j'ai un message d'erreur : Property access must assign to the property or use its value.
ci joint le code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = Score
Dim Placement As New Random
Dim CarteTiree As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim Table(16, 3) As Integer
Randomize()
For j = 0 To 3
Table(j, 2) = 20
Table(j * 4, 1) = 15
Next j
For k = 0 To 3
Table(k + 4, 2) = 95
Table(k * 4 + 1, 1) = 92
Next k
For l = 0 To 3
Table(l + 8, 2) = 170
Table(l * 4 + 2, 1) = 169
Next l
For m = 0 To 3
Table(m + 12, 2) = 245
Table(m * 4 + 3, 1) = 246
Next m