title: How to accumulate the sum in VB?
body: <pre><code>        Dim index As Integer
          Dim choice As String
          Dim total As Integer
  
          total = 0
  
          index = NumericUpDown1.Value
  
  
          Dim arr(4) As Integer
          arr(0) = 10
          arr(1) = 5
          arr(2) = 21
          arr(3) = 33
  
  
  
  
          If index &gt; 0 Then
              choice = (Combobox1.SelectedItem.ToString + " x " + NumericUpDown1.Value.ToString)
              ListBox1.Items.Add(choice)
              CheckedListBox1.Items.Add(choice)
              total += arr(Combobox1.SelectedIndex) * index
              TotalLabel.Text = total.ToString()
  
  
        Else
              MsgBox("error.")
  
          End If
  </code></pre>
  
  <p>I can calculate the total of single choice, but fail to accumulate to sum.
  What's wrong of the code?</p>
  
  <p>Current Situation:
  <strong>Step 1:</strong>
  choose arr(0), index = 2
  total = 20</p>
  
  <p><strong>Step 2:</strong>
  choose arr(2), index = 1
  total = 21</p>
  
  <p>Correct Situation:
  <strong>Step 1:</strong>
  choose arr(0), index = 2
  total = 20</p>
  
  <p><strong>Step 2:</strong>
  choose arr(2), index = 1
  total = 41</p>