You are viewing our Forum Archives. To view or take place in current topics click here.
Visual Basic Logic Help
Posted:

Visual Basic Logic HelpPosted:

Lood
  • Blind Luck
Status: Offline
Joined: Apr 18, 201113Year Member
Posts: 1,175
Reputation Power: 911
Status: Offline
Joined: Apr 18, 201113Year Member
Posts: 1,175
Reputation Power: 911
Hello everyone,

I have a program that I am working on in Visual Basic. I was wondering if I could get some help.

My program collects grades entered by the user and then finds their average. That all works fine. After that it is supposed to find how many grades are above the average.

Here is my code:

Public Class Form1
'Clicking the record button enters the grade to the list box, clears the grade box, and moves the focus back to it
Private Sub btnRecord_Click(sender As Object, e As EventArgs) Handles btnRecord.Click
lstGrades.Items.Add(txtGrade.Text)
txtGrade.Clear()
txtGrade.Focus()
End Sub

Private Sub btncalculate_click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim sum As Double = 0
Dim maxgrade As Double = 0
Dim average As Double
Dim counter As Integer

If lstGrades.Items.Count > 0 Then
For i As Integer = 0 To lstGrades.Items.Count - 1
sum += CDbl(lstGrades.Items(i))
If CDbl(lstGrades.Items(i)) Then
maxgrade = CDbl(lstGrades.Items(i))
End If
Next
average = (sum / lstGrades.Items.Count).ToString("n")
txtAverage.Text = average
If counter >= average Then
counter += 1
End If
txtHighest.Text = CStr(counter)
Else
MessageBox.Show("you must first enter some grades.")
End If
End Sub
End Class


Thanks in advance!
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.