I have a for loop that changes from 0 to 4, 5 to 9, 10 to 14, 15 to 19, then 20 to 24 each time i hit the play button. (both numbers in the range determined by a variable called CheckDynamicA and CheckDynamicB.
Each set of 5 numbers is 5 check boxes representing a player in my game im designing.
It works except for the last time I hit the "play button"
Each time I hit the play button a variable called T is given T = T + 1.
One the last click of the play button I have decision logic that turns T back to 0, and should bring the 20 to 24 back to 0 to 4.
My problem is on the last click of the button though, as the debugger says that the value of the variable = 25, and not 24, which is out of range. No where in my code (ive checked dozens of times for errors) do I have it set to 25 in the "19 to 24", and no where does it add +1 to the max range.
Each set of 5 numbers is 5 check boxes representing a player in my game im designing.
It works except for the last time I hit the "play button"
Each time I hit the play button a variable called T is given T = T + 1.
One the last click of the play button I have decision logic that turns T back to 0, and should bring the 20 to 24 back to 0 to 4.
My problem is on the last click of the button though, as the debugger says that the value of the variable = 25, and not 24, which is out of range. No where in my code (ive checked dozens of times for errors) do I have it set to 25 in the "19 to 24", and no where does it add +1 to the max range.
Code:
Private Sub PlayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayButton.Click
Dim CardCheckBoxArray() As CheckBox = {CardCheckBox1, CardCheckBox2, CardCheckBox3, CardCheckBox4, CardCheckBox5, CardCheckBox6, CardCheckBox7, CardCheckBox8, CardCheckBox9, _
CardCheckBox10, CardCheckBox11, CardCheckBox12, CardCheckBox13, CardCheckBox14, CardCheckBox15, CardCheckBox16, CardCheckBox17, _
CardCheckBox18, CardCheckBox19, CardCheckBox20, CardCheckBox21, CardCheckBox22, CardCheckBox23, CardCheckBox24, CardCheckBox25}
Dim HitPoints() As Label = {Nothing, HitPoints1, HitPoints2, HitPoints3, HitPoints4, HitPoints5}
Dim n As Integer
Dim DisableCheckBoxInteger As Integer
'fail safe to make sure checkboxes are checked
If CardCheckBox1.Checked = False And CardCheckBox2.Checked = False And CardCheckBox3.Checked = False And CardCheckBox4.Checked = False And CardCheckBox5.Checked = False And CardCheckBox6.Checked = False And _
CardCheckBox7.Checked = False And CardCheckBox8.Checked = False And CardCheckBox9.Checked = False And CardCheckBox10.Checked = False And CardCheckBox11.Checked = False And CardCheckBox12.Checked = False And _
CardCheckBox13.Checked = False And CardCheckBox14.Checked = False And CardCheckBox15.Checked = False And CardCheckBox16.Checked = False And CardCheckBox17.Checked = False And CardCheckBox18.Checked = False And _
CardCheckBox19.Checked = False And CardCheckBox20.Checked = False And CardCheckBox21.Checked = False And CardCheckBox22.Checked = False And CardCheckBox23.Checked = False And CardCheckBox24.Checked = False And _
CardCheckBox25.Checked = False Then
WarningLabel.Text = "Please select your card(s)"
Else
'Player 1
For Me.Checks = ChecksDynamicA To ChecksDynamicB
If T = 0 And CardCheckBoxArray(Checks).Checked = True Then
For DisableCheckBoxInteger = 0 To 24
Select Case DisableCheckBoxInteger
Case 0 To 4
CardCheckBoxArray(DisableCheckBoxInteger).Visible = False
Case 5 To 9
CardCheckBoxArray(DisableCheckBoxInteger).Visible = True
Case 10 To 24
CardCheckBoxArray(DisableCheckBoxInteger).Visible = False
End Select
Next DisableCheckBoxInteger
AtkPlayerDialog.Player1.Enabled = False
AtkPlayerDialog.Player2.Enabled = True
AtkPlayerDialog.Player3.Enabled = True
AtkPlayerDialog.Player4.Enabled = True
AtkPlayerDialog.Player5.Enabled = True
ChecksDynamicA = 0
ChecksDynamicB = 4
'Player 2
ElseIf T = 1 And CardCheckBoxArray(Checks).Checked = True Then
For DisableCheckBoxInteger = 0 To 24
Select Case DisableCheckBoxInteger
Case 0 To 9
CardCheckBoxArray(DisableCheckBoxInteger).Visible = False
Case 10 To 14
CardCheckBoxArray(DisableCheckBoxInteger).Visible = True
Case 15 To 24
CardCheckBoxArray(DisableCheckBoxInteger).Visible = False
End Select
Next DisableCheckBoxInteger
AtkPlayerDialog.Player1.Enabled = True
AtkPlayerDialog.Player2.Enabled = False
AtkPlayerDialog.Player3.Enabled = True
AtkPlayerDialog.Player4.Enabled = True
AtkPlayerDialog.Player5.Enabled = True
ChecksDynamicA = 5
ChecksDynamicB = 9
'Player 3
ElseIf T = 2 And CardCheckBoxArray(Checks).Checked = True Then
For DisableCheckBoxInteger = 0 To 24
Select Case DisableCheckBoxInteger
Case 0 To 14
CardCheckBoxArray(DisableCheckBoxInteger).Visible = False
Case 15 To 19
CardCheckBoxArray(DisableCheckBoxInteger).Visible = True
Case 20 To 24
CardCheckBoxArray(DisableCheckBoxInteger).Visible = False
End Select
Next DisableCheckBoxInteger
AtkPlayerDialog.Player1.Enabled = True
AtkPlayerDialog.Player2.Enabled = True
AtkPlayerDialog.Player3.Enabled = False
AtkPlayerDialog.Player4.Enabled = True
AtkPlayerDialog.Player5.Enabled = True
ChecksDynamicA = 10
ChecksDynamicB = 14
'Player 4
ElseIf T = 3 And CardCheckBoxArray(Checks).Checked = True Then
For DisableCheckBoxInteger = 0 To 24
Select Case DisableCheckBoxInteger
Case 0 To 19
CardCheckBoxArray(DisableCheckBoxInteger).Visible = False
Case 20 To 24
CardCheckBoxArray(DisableCheckBoxInteger).Visible = True
End Select
Next DisableCheckBoxInteger
AtkPlayerDialog.Player1.Enabled = True
AtkPlayerDialog.Player2.Enabled = True
AtkPlayerDialog.Player3.Enabled = True
AtkPlayerDialog.Player4.Enabled = False
AtkPlayerDialog.Player5.Enabled = True
ChecksDynamicA = 15
ChecksDynamicB = 19
'Player 5
ElseIf T = 4 And CardCheckBoxArray(Checks).Checked = True Then
For DisableCheckBoxInteger = 0 To 24
Select Case DisableCheckBoxInteger
Case 0 To 4
CardCheckBoxArray(DisableCheckBoxInteger).Visible = True
Case 5 To 24
CardCheckBoxArray(DisableCheckBoxInteger).Visible = False
End Select
Next DisableCheckBoxInteger
AtkPlayerDialog.Player1.Enabled = True
AtkPlayerDialog.Player2.Enabled = True
AtkPlayerDialog.Player3.Enabled = True
AtkPlayerDialog.Player4.Enabled = True
AtkPlayerDialog.Player5.Enabled = False
ChecksDynamicA = 20
ChecksDynamicB = 24
End If
Next Checks
'Code for choosing which player to attack
AtkPlayerDialog.ShowDialog()
If AtkPlayerDialog.DialogResult = 1 Then
n = 1
ElseIf AtkPlayerDialog.DialogResult = 2 Then
n = 2
ElseIf AtkPlayerDialog.DialogResult = 3 Then
n = 3
ElseIf AtkPlayerDialog.DialogResult = 4 Then
n = 4
ElseIf AtkPlayerDialog.DialogResult = 5 Then
n = 5
End If
'CheckedLoop
For Me.Checks = ChecksDynamicA To ChecksDynamicB
'Supplement Numbers(1-5) variable in loop
If Checks = Checks Then
NumberChecks = NumberArray(Checks)
End If
'Play Card(s)
If T = 0 Then
If CardCheckBoxArray(Checks).Checked = True AndAlso Player1HandGroup(NumberChecks).QuantityInteger > 0 Then
'Subtract Hitpoints when damage is delt
Player1HandGroup(n).HitPoints -= Player1HandGroup(NumberChecks).DamageInteger
HitPoints(n).Text = Player1HandGroup(n).HitPoints.ToString
'When player plays hand, card quantity is removed from hand to the discard pile.
If Player1HandGroup(NumberChecks).CardType = "Weapon" Then
DiscardDialog.ShowDialog()
'Choose if to Discard Weapon after usage
If DiscardDialog.DialogResult = Windows.Forms.DialogResult.OK Then
Call GrabFromDeckAndDiscard()
End If
Else
Call GrabFromDeckAndDiscard()
End If
End If
ElseIf T = 1 Then
If CardCheckBoxArray(Checks).Checked = True AndAlso Player1HandGroup(NumberChecks).QuantityInteger2 > 0 Then
'Subtract Hitpoints when damage is delt
Player1HandGroup(n).HitPoints -= Player1HandGroup(NumberChecks).DamageInteger
HitPoints(n).Text = Player1HandGroup(n).HitPoints.ToString
'When player plays hand, card quantity is removed from hand to the discard pile.
If Player1HandGroup(NumberChecks).CardType = "Weapon" Then
DiscardDialog.ShowDialog()
'Choose if to Discard Weapon after usage
If DiscardDialog.DialogResult = Windows.Forms.DialogResult.OK Then
Call GrabFromDeckAndDiscard()
End If
Else
Call GrabFromDeckAndDiscard()
End If
End If
ElseIf T = 2 Then
If CardCheckBoxArray(Checks).Checked = True AndAlso Player1HandGroup(NumberChecks).QuantityInteger3 > 0 Then
'Subtract Hitpoints when damage is delt
Player1HandGroup(n).HitPoints -= Player1HandGroup(NumberChecks).DamageInteger
HitPoints(n).Text = Player1HandGroup(n).HitPoints.ToString
'When player plays hand, card quantity is removed from hand to the discard pile.
If Player1HandGroup(NumberChecks).CardType = "Weapon" Then
DiscardDialog.ShowDialog()
'Choose if to Discard Weapon after usage
If DiscardDialog.DialogResult = Windows.Forms.DialogResult.OK Then
Call GrabFromDeckAndDiscard()
End If
Else
Call GrabFromDeckAndDiscard()
End If
End If
ElseIf T = 3 Then
If CardCheckBoxArray(Checks).Checked = True AndAlso Player1HandGroup(NumberChecks).QuantityInteger4 > 0 Then
'Subtract Hitpoints when damage is delt
Player1HandGroup(n).HitPoints -= Player1HandGroup(NumberChecks).DamageInteger
HitPoints(n).Text = Player1HandGroup(n).HitPoints.ToString
'When player plays hand, card quantity is removed from hand to the discard pile.
If Player1HandGroup(NumberChecks).CardType = "Weapon" Then
DiscardDialog.ShowDialog()
'Choose if to Discard Weapon after usage
If DiscardDialog.DialogResult = Windows.Forms.DialogResult.OK Then
Call GrabFromDeckAndDiscard()
End If
Else
Call GrabFromDeckAndDiscard()
End If
End If
ElseIf T = 4 Then
If CardCheckBoxArray(Checks).Checked = True AndAlso Player1HandGroup(NumberChecks).QuantityInteger5 > 0 Then
'Subtract Hitpoints when damage is delt
Player1HandGroup(n).HitPoints -= Player1HandGroup(NumberChecks).DamageInteger
HitPoints(n).Text = Player1HandGroup(n).HitPoints.ToString
'When player plays hand, card quantity is removed from hand to the discard pile.
If Player1HandGroup(NumberChecks).CardType = "Weapon" Then
DiscardDialog.ShowDialog()
'Choose if to Discard Weapon after usage
If DiscardDialog.DialogResult = Windows.Forms.DialogResult.OK Then
Call GrabFromDeckAndDiscard()
End If
Else
Call GrabFromDeckAndDiscard()
End If
End If
End If
ChecksLabel.Text = Checks.ToString
Next
T += 1
CardCheckBoxArray(Checks).Checked = False
If T = 5 Then
T = 0
End If
End If
End Sub
Comment