1 pièce(s) jointe(s)
incrémentation nombre sur plusieurs interfaces
Bonjour à vous.
Etant débutant je crée des exercices d'entrainement.
Dans cet exercice je tombe sur un problème que j'arrive à résoudre tout seul
Pièce jointe 177386
Le but est d'activer le RadioButton adéquat (le continent où se trouve le pays en question). si c'est le bon RadioButton on gagne 100 points sinon on perd 100.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| Public Class Pays
Public nom As String
Public bon_choix As Integer
Public amerique As String
Public asie As String
Public europe As String
Public afrique As String
' Public Shared score As Integer = 0
Public Sub New(ByVal nnom As String, ByVal bchoix As Integer)
Me.nom = nnom
Me.bon_choix = bchoix
Me.amerique = "Amerique"
Me.europe = "Europe"
Me.afrique = "Afrique"
Me.asie = "Asie"
End Sub
End Class |
Code:
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| Public Class Form1
Dim tablo(7) As Pays
Dim indice As Integer = -1
Dim score As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' ===== Création des objets ========
Dim b1 As New Pays("Tunisie", 2)
ReDim Preserve tablo(0)
tablo(0) = b1
Dim b2 As New Pays("Norvège", 4)
ReDim Preserve tablo(1)
tablo(1) = b2
Dim b3 As New Pays("Brésil", 1)
ReDim Preserve tablo(2)
tablo(2) = b3
Dim b4 As New Pays("Chine", 3)
ReDim Preserve tablo(3)
tablo(3) = b4
Dim b5 As New Pays("Nepal", 3)
ReDim Preserve tablo(4)
tablo(4) = b5
Dim b6 As New Pays("France", 4)
ReDim Preserve tablo(5)
tablo(5) = b6
Dim b7 As New Pays("Maroc", 2)
ReDim Preserve tablo(6)
tablo(6) = b7
Dim b8 As New Pays("Canada", 1)
ReDim Preserve tablo(7)
tablo(7) = b8
'==== Décocher tous les radiobutton ====
For Each rdb In Controls.OfType(Of RadioButton)()
rdb.Checked = False
Next
' === Affichage fenêtre ====
affiche_suivant()
End Sub
' === sub Affichage ====
Public Sub affiche_suivant()
If (indice < tablo.Length - 1) Then
indice += 1
Me.Label1.Text = tablo(indice).nom
Me.RadioButton1.Text = tablo(indice).amerique
Me.RadioButton2.Text = tablo(indice).afrique
Me.RadioButton3.Text = tablo(indice).asie
Me.RadioButton4.Text = tablo(indice).europe
Me.Label2.Text = score.ToString
Else
Me.Button1.Enabled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Select Case Me.tablo(indice).bon_choix
Case 1
If (Me.RadioButton1.Checked = True) Then
score += 100
Else
score -= 100
End If
Case 2
If (Me.RadioButton2.Checked = True) Then
score += 100
Else
score -= 100
End If
Case 3
If (Me.RadioButton3.Checked = True) Then
score += 100
Else
score -= 100
End If
Case 4
If (Me.RadioButton4.Checked = True) Then
score += 100
Else
score -= 100
End If
End Select
affiche_suivant()
End Sub
End Class |
Le problème au dernier clic sur Button il n'a pas d'incrémentation du score (8 réponses juste, donnent 700 points), pourquoi?
Merci