Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking every variable in this code Dynamic Visual Basic 2010
    primarykey
    data
    text
    <p>Sorry for the long piece of code. In a game I'm designing, I have this code starting at the checkbox.checked if statement currently repeated 5 times for each checkbox clicked--each checkbox is equal to a card within the players hand in the game.</p> <p>What I'd like to know is what can I do to make it mostly dynamic. Namely the CardCheckBox1.Checked Object/Method. As stated above the code is repeated 5 times, as I have 5 existing checkboxes. Is there a way to place the checkboxes into an array or collection so when I click a check box and hit the play button it will be the equivalent of hitting CardCheckBox2.checked = true, CardCheckBox2.checked = true, etc. Once I figure how to make that part dynamic I can finally start making the rest of the code dynamic, because I assume procedure for making a dynamic label code would be very similar to the checkboxes, etc.</p> <p>I've had </p> <pre><code>Dim CardCheckBoxArray() As CheckBox = {CardCheckBox1, CardCheckBox2, CardCheckBox3, CardCheckBox4, CardCheckBox5} </code></pre> <p>posted at the Modular Level, in the Form_Load Procedure, and even the Play_Button Procedure, but I always end up with a nullreference exception on the CardCheckBox(n).Checked Portion of the code when I do</p> <pre><code>If CardCheckBoxArray(0).Checked = True And Player1HandGroup(Number1).QuantityInteger &gt; 0 Then </code></pre> <p>So I don't know where to go with it. The long piece of code is my entire PlayButton_Click procedure, except for the other CardCheckBox if statements.</p> <pre><code>Private Sub PlayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayButton.Click Dim n As Integer Dim WeaponDiscardInteger As Integer = 1 AtkPlayerDialog.ShowDialog() 'Code for choosing which player to attack If AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.Cancel Then n = 2 ElseIf AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.OK Then n = 1 ElseIf AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.Abort Then n = 3 ElseIf AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.Retry Then n = 4 ElseIf AtkPlayerDialog.DialogResult = Windows.Forms.DialogResult.Ignore Then n = 5 End If 'playing card 1 If CardCheckBox1.Checked = True And Player1HandGroup(Number1).QuantityInteger &gt; 0 Then 'Subtract Hitpoints when damage is delt Player1HandGroup(n).HitPoints -= Player1HandGroup(Number1).DamageInteger HitPoints1.Text = Player1HandGroup(1).HitPoints.ToString HitPoints2.Text = Player1HandGroup(2).HitPoints.ToString HitPoints3.Text = Player1HandGroup(3).HitPoints.ToString HitPoints4.Text = Player1HandGroup(4).HitPoints.ToString HitPoints5.Text = Player1HandGroup(5).HitPoints.ToString 'When player plays hand, card quantity is removed from hand to discard pile. Player1HandGroup(Number1).QuantityInteger -= 1 DiscardGroup(Number1).QuantityInteger += 1 'Shuffle Deck from Discard Pile if Deck is out of cards Call DiscardPile() 'Reset Number Generator, unless weapon isn't discard Number = (DeckGroup(Rnd.Next(0, DeckGroup.Count)).ID) If DeckGroup(Number).QuantityInteger &gt; 0 Then 'Grab New Card From Deck DeckGroup(Number).QuantityInteger -= 1 Player1HandGroup(Number).QuantityInteger += 1 Card1Type = Player1HandGroup(Number).CardType CardCheckBox1.Text = Player1HandGroup(Number).CardNameString Number1 = Number Else Call PlayElse() End If </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload