none
Listbox to display the average

    Question

  • this application calculate and display the average score of 6 judges

    so one listbox for the names of the persons and other for the score from 0 to 10

    after a person score  has been reorded reove from the list , this prevent the user from entering a judge's score more than once.

    this is my NameListBox:       ScoreListBox:  0 to 10

    Robert                                        

    Linda                                             

    Louis

    Rosa

    David

    Jane

    So if i select Linda and she give a score of 5; then Rosa 9, robert 9,david 8,Loius 8,and Jane 7

     on the Lbl Avg shuold appera the avg = 7.67

    anyway that is the idea here is my code:

     

    Private Sub frmPowder_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ' Add names to the Nameslistbox

    NamesListBox.Items.Add("Robert")

    NamesListBox.Items.Add("Linda")

    NamesListBox.Items.Add("Louis")

    NamesListBox.Items.Add("Rosa")

    NamesListBox.Items.Add("David")

    NamesListBox.Items.Add("Jane")

    'Add scores to the scorelistbox

    For score As Integer = 0 To 10

    ScoreListBox.Items.Add(score.ToString)

    Next

    NamesListBox.SelectedItem = "David"

    ScoreListBox.SelectedItem = "0"

    End Sub

    Private Sub LblCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LblCalc.Click

    Dim score As Integer

    Dim numberOfScores As Integer 'Counter

    Dim totalScores As Integer 'accumulator

    Dim avg As Decimal

    Dim names As String

    names = Convert.ToString(Me.NamesListBox.SelectedItem)

    If Name = "Robert" Then

    score = Convert.ToInt32(Me.ScoreListBox.SelectedItem) + 1

    ElseIf Name = "Linda" Then

    score = Convert.ToInt32(Me.ScoreListBox.SelectedItem) + 1

    End If

    avg = score / 2

    Me.LblAvg.Text = avg.ToString("n2")

    Sunday, June 10, 2007 11:42 PM

Answers

  • Code Snippet

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Static marks(NamesListBox.Items.Count) As Byte

    Static i As Byte = 0

    marks(i) = ScoreListBox.SelectedItem

    NamesListBox.Items.Remove(NamesListBox.SelectedItem)

    NamesListBox.SelectedIndex = 0

    ScoreListBox.SelectedIndex = 0

    Dim tot As Byte

    For j As Byte = 0 To i

    tot += marks(j)

    Next

    i += 1

    LblAvg.Text = tot / i

    If NamesListBox.Items.Count = 0 Then

    Button2.Enabled = False

    End If

    End Sub

     

    Add a button and try this out Smile

    Monday, June 11, 2007 10:30 AM

All replies

  • Code Snippet

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    Static marks(NamesListBox.Items.Count) As Byte

    Static i As Byte = 0

    marks(i) = ScoreListBox.SelectedItem

    NamesListBox.Items.Remove(NamesListBox.SelectedItem)

    NamesListBox.SelectedIndex = 0

    ScoreListBox.SelectedIndex = 0

    Dim tot As Byte

    For j As Byte = 0 To i

    tot += marks(j)

    Next

    i += 1

    LblAvg.Text = tot / i

    If NamesListBox.Items.Count = 0 Then

    Button2.Enabled = False

    End If

    End Sub

     

    Add a button and try this out Smile

    Monday, June 11, 2007 10:30 AM
  • thanks a lot Karl , that is exactly what I need to do.
    Tuesday, June 12, 2007 1:39 AM