JarrodMadd

I have an assignment and I am stuck on one thing. A part of the assignment is to make the NumericUpDown and have the value changes in the NumericUpDown control, change the average using the ValueChanged event of the NumericUpDown control. Basically, as the arrows are clicked up or down, the average needs to change automatically. This program is a Grade Average Calculator for testing 3 Grade scores and then testing to get another average after the lowest is dropped. It also displays a letter grade.

I am currently using VB Express 2005 and I think it is a great program. A quick response would be greatly appreciated.

My code is as follows:

Public Class Form1

Private Sub BtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReset.Click

NumTest1.Value = 0

NumTest2.Value = 0

NumTest3.Value = 0

TxtAvg3.Text = "0"

TxtLetter1.Text = " "

TxtHigh.Text = "0"

TxtLow.Text = "0"

TxtAvg2.Text = "0"

TxtLetter2.Text = " "

End Sub

Private Sub BtnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalculate.Click

'Calculates the Average grade based on all 3 grades entered.

TxtAvg3.Text = (NumTest1.Value + NumTest2.Value + NumTest3.Value) / 3

' Performs calculations to find HIGH and LOW score based on data entered.

If NumTest1.Value > NumTest2.Value And NumTest1.Value > NumTest3.Value Then

TxtHigh.Text = NumTest1.Value

Else

If NumTest2.Value > NumTest1.Value And NumTest2.Value > NumTest3.Value Then

TxtHigh.Text = NumTest2.Value

Else

If NumTest3.Value > NumTest1.Value And NumTest3.Value > NumTest2.Value Then

TxtHigh.Text = NumTest3.Value

End If

End If

End If

If NumTest1.Value < NumTest2.Value And NumTest1.Value < NumTest3.Value Then

TxtLow.Text = NumTest1.Value

Else

If NumTest2.Value < NumTest1.Value And NumTest2.Value < NumTest3.Value Then

TxtLow.Text = NumTest2.Value

Else

If NumTest3.Value < NumTest1.Value And NumTest3.Value < NumTest2.Value Then

TxtLow.Text = NumTest3.Value

End If

End If

End If

'Calculates the LETTER GRADE for the 3 GRADE AVERAGE and places the corresponding letter.

If TxtAvg3.Text <= 100 And TxtAvg3.Text >= 90 Then

TxtLetter1.Text = "A"

Else

If TxtAvg3.Text <= 89 And TxtAvg3.Text >= 80 Then

TxtLetter1.Text = "B"

Else

If TxtAvg3.Text <= 79 And TxtAvg3.Text >= 70 Then

TxtLetter1.Text = "C"

Else

If TxtAvg3.Text <= 69 And TxtAvg3.Text >= 60 Then

TxtLetter1.Text = "D"

Else

If TxtAvg3.Text <= 59 Then

TxtLetter1.Text = "F"

End If

End If

End If

End If

End If

'Calculates the GRADE AVERAGE after dropping the lowest grade.

If NumTest1.Value < NumTest2.Value And NumTest1.Value < NumTest3.Value Then

TxtAvg2.Text = (NumTest2.Value + NumTest3.Value) / 2

Else

If NumTest2.Value < NumTest1.Value And NumTest2.Value < NumTest3.Value Then

TxtAvg2.Text = (NumTest1.Value + NumTest3.Value) / 2

Else

If NumTest3.Value < NumTest1.Value And NumTest3.Value < NumTest2.Value Then

TxtAvg2.Text = (NumTest1.Value + NumTest2.Value) / 2

End If

End If

End If

'Calculates the LETTER GRADE of the two highest test scores averaged.

If TxtAvg2.Text <= 100 And TxtAvg2.Text >= 90 Then

TxtLetter2.Text = "A"

Else

If TxtAvg2.Text <= 89 And TxtAvg2.Text >= 80 Then

TxtLetter2.Text = "B"

Else

If TxtAvg2.Text <= 79 And TxtAvg2.Text >= 70 Then

TxtLetter2.Text = "C"

Else

If TxtAvg2.Text <= 69 And TxtAvg2.Text >= 60 Then

TxtLetter2.Text = "D"

Else

If TxtAvg2.Text <= 59 Then

TxtLetter2.Text = "F"

End If

End If

End If

End If

End If

End Sub

Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click

Me.Close()

End Sub

End Class




Re: Visual Basic Express Edition NumericUpDown Control (ValueChanged event)

Tall Dude

I'm not sure I understand exactly what you are doing

but I think you want to change BtnCalculate_Click to

a regular sub :

Private sub Calculate()

... all your code .....

End Sub

Then add:

Private Sub UpDown_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) _

Handles NumTest1.ValueChanged, NumTest2.ValueChanged, NumTest3.ValueChanged

Calculate()

End Sub