title: Visual Basic listbox with loop to determine a total score and average
body: <p>I am new to <code>VB</code> and I need to create a program for a skating rink.  The number of judges varies from week to week and at the end of each skater's routine each judge assigns a score <em>0-10</em> to the skater.  The application needs to allow the manger of the rink to enter each judge's score for a specific skater.  It should also calculate and display the <code>skater's average</code>, <code>the number of scores entered</code>, and the <code>total score</code>.  You select each score from a <code>List box</code> and then click the <code>Record Score button</code>.  </p>
  
  <p>I have no idea where to go next.  Everything is incorrect when you select the first score from the <code>list box</code> and its also re-adding the score to the bottom of the <code>list box</code>.  Below is the code and any help is appreciated.</p>
  
  <p>Thanks!</p>
  
  <pre><code>Option Explicit On
  Option Strict On
  Option Infer Off
  
  Public Class frmMain
  
      Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
         Me.Close()
      End Sub
  
      Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
          'Fill list box with values
  
          For intScore As Integer = 0 To 10 Step 1
              lstScore.Items.Add(intScore.ToString)
          Next intScore
          lstScore.SelectedItem = "0"
  
      End Sub
  
      Private Sub btnRecordScore_Click(sender As Object, e As EventArgs) Handles btnRecordScore.Click
          'accumulates the scores for each skater
          Dim intScore As Integer
          Dim intNumScores As Integer
          Dim intTotalScore As Integer
          Dim decAvgScore As Decimal
  
          Integer.TryParse(lstScore.SelectedItem.ToString, intScore)
  
          'add score to score 
          lstScore.Items.Add(lstScore.SelectedItem)
  
          'update average
          intNumScores = 0
          intTotalScore = 0
          For Each selScore As Object In lstScore.Items
              If Integer.TryParse(selScore.ToString, intScore) Then
                  intNumScores = intNumScores + intScore
                  intTotalScore = intTotalScore + 1
              End If
          Next
          decAvgScore = intNumScores \ intTotalScore
          lblTotalScore.Text = intNumScores.ToString
          lblNumScores.Text = intTotalScore.ToString
          lblAvgScore.Text = decAvgScore.ToString("N1")
      End Sub
  
      Private Sub btnNextSkater_Click(sender As Object, e As EventArgs) Handles btnNextSkater.Click
          'clears screen, sets focus
          lblTotalScore.Text = String.Empty
          lblNumScores.Text = String.Empty
          lblAvgScore.Text = String.Empty
          lstScore.Focus()
      End Sub
  End Class
  </code></pre>