Hulp nodig met VBA code

Status
Niet open voor verdere reacties.

Shambles

Nieuwe gebruiker
Lid geworden
15 jan 2010
Berichten
3
Hallo,
Ik ben bezig met Yahtzee te maken in VBA maar krijg het maar niet voor elkaar om de scores automatisch opgeteld te krijgen in de tekstbox. Zou fijn zijn als een van jullie ff kon kijken of ik de code juist heb.

Dim Score As Byte
Dim Teller As Byte
Private Sub CommandButton1_Click()
If Teller < 3 Then
If Me.CheckBox1.Value = False Then
Me.CommandButton6.Caption = (Int(Rnd * 6) + 1)
Me.CommandButton5.Caption = (Int(Rnd * 6) + 1)
Me.CommandButton4.Caption = (Int(Rnd * 6) + 1)
Me.CommandButton3.Caption = (Int(Rnd * 6) + 1)
Me.CommandButton2.Caption = (Int(Rnd * 6) + 1)
End If
Teller = Teller + 1
End If
If Teller > 3 Then Teller = 0
End Sub
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = False Then
Me.CommandButton6.Caption = (Int(Rnd * 6) + 1)
Me.CommandButton5.Caption = (Int(Rnd * 6) + 1)
Me.CommandButton4.Caption = (Int(Rnd * 6) + 1)
Me.CommandButton3.Caption = (Int(Rnd * 6) + 1)
Me.CommandButton2.Caption = (Int(Rnd * 6) + 1)
End If
End Sub
Private Sub Label1_Click()
If CommandButton6 = 1 Then Score = Score + 1
If CommandButton5 = 1 Then Score = Score + 1
If CommandButton4 = 1 Then Score = Score + 1
If CommandButton3 = 1 Then Score = Score + 1
If CommandButton2 = 1 Then Score = Score + 1
Me.TextBox1.Value = Score
Teller = 0
End Sub

Private Sub Label2_Click()
If CommandButton6 = 2 Then Score = Score + 2
If CommandButton5 = 2 Then Score = Score + 2
If CommandButton4 = 2 Then Score = Score + 2
If CommandButton3 = 2 Then Score = Score + 2
If CommandButton2 = 2 Then Score = Score + 2
Me.TextBox2.Value = Score
Teller = 0
End Sub


Private Sub Label3_Click()
If CommandButton6 = 3 Then Score = Score + 3
If CommandButton5 = 3 Then Score = Score + 3
If CommandButton4 = 3 Then Score = Score + 3
If CommandButton3 = 3 Then Score = Score + 3
If CommandButton2 = 3 Then Score = Score + 3
Me.TextBox3.Value = Score
Teller = 0
End Sub

Private Sub Label4_Click()
If CommandButton6 = 4 Then Score = Score + 4
If CommandButton5 = 4 Then Score = Score + 4
If CommandButton4 = 4 Then Score = Score + 4
If CommandButton3 = 4 Then Score = Score + 4
If CommandButton2 = 4 Then Score = Score + 4
Me.TextBox4.Value = Score
Teller = 0
End Sub

Private Sub Label5_Click()
If CommandButton6 = 5 Then Score = Score + 5
If CommandButton5 = 5 Then Score = Score + 5
If CommandButton4 = 5 Then Score = Score + 5
If CommandButton3 = 5 Then Score = Score + 5
If CommandButton2 = 5 Then Score = Score + 5
Me.TextBox5.Value = Score
Teller = 0
End Sub

Private Sub Label6_Click()
If CommandButton6 = 6 Then Score = Score + 6
If CommandButton5 = 6 Then Score = Score + 6
If CommandButton4 = 6 Then Score = Score + 6
If CommandButton3 = 6 Then Score = Score + 6
If CommandButton2 = 6 Then Score = Score + 6
Me.TextBox6.Value = Score
Teller = 0
End Sub
 
Vertel eens in een paar woorden hoe het had moeten werken.
(Want in jouw code kan ik even geen 'plan' terugvinden.)

Je hebt zes commandbuttons en zes labels en een checkbox ... en dan?
 
Bedankt voor je reactie Evert
Het plan is dat ik wil dat de geworpen aantallen worden opgeteld en in textbox1 verschijnen. (textbox1 is voor de eenen)

Ik had dit hiervoor:
Private Sub Label1_Click()
If CommandButton6 = 1 Then Score = Score + 1
If CommandButton5 = 1 Then Score = Score + 1
If CommandButton4 = 1 Then Score = Score + 1
If CommandButton3 = 1 Then Score = Score + 1
If CommandButton2 = 1 Then Score = Score + 1
Me.TextBox1.Value = Score
Teller = 0
End Sub

de commandbuttons zijn dus de dobbelstenen. Maar elke keer als ik op het label click verschijnt er alleen een 0. De eenen worden niet opgeteld. Als ik weet hoe dit opgelost moet worden kom ik er zelf verder wel uit. Alvast bedankt!
 
Code:
If CommandButton6.Caption = "1" Then Score = Score + 1
(dus met aanhalingstekens, want CommandButton6.Caption bevat een string-waarde.
 
EDIT: Het is gelukt, bedankt voor de hulp evert!
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan