Back to Examples
Public Class frmGrade

  Dim intGrade(10) As Integer
  Dim intCounter As Integer = 0

  Private Sub btnAddGrade_Click(sender As Object, e As EventArgs) Handles btnAddGrade.Click
    If IsNumeric(txtGradeEntry.Text) Then
      intGrade(intCounter) = txtGradeEntry.Text
      intCounter = intCounter + 1
    Else
      MessageBox.Show(“Please enter a valid number.”)
      lblAverage.Text = “”
    End If

    txtGradeEntry.Text = “”
  End Sub
  Private Sub btnAverage_Click(sender As Object, e As EventArgs) Handles btnAverage.Click

    Dim intCountemp As Integer = 0
    Dim intSum As Integer = 0
    Dim decAverage As Decimal = 0

    If intCounter = 0 Then
      MessageBox.Show(“Please enter at least one valid grade.”)
      lblAverage.Text = “”
    Else
      Do
        intSum = intGrade(intCountemp) + intSum
        intCountemp = intCountemp + 1
      Loop Until intCountemp = intCounter
      decAverage = intSum / intCounter
      lblAverage.Text = “The average grade is ” & decAverage
      intCounter = 0
    End If

  End Sub

  Private Sub txtGradeEntry_TextChanged(sender As Object, e As EventArgs) Handles txtGradeEntry.TextChanged

    lblAverage.Text = “”
  End Sub

End Class
Back to Examples

Startup Discount
Small Business?
Contact us for an Enormous Discount!