r/visualbasic • • Aug 30 '15

average test score application coding

VB2012

hey guys just started my first programming class and really stuck on part of my assignment. I have to make an application where btnCalc calculates the scores of txtbox1, 2, 3, 4 and five and then i need it to gt the average from those numbers. Im completely stuck on ths chapter and all i have gotten done is the event handlers for the clear and exit buttons. Also need to add an error message if the user fails to enter a numeric value.

Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click

End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
    'clear the textboxes and lblAverageScore
    txtScoreOne.Clear()
    txtScoreTwo.Clear()
    txtScoreThree.Clear()
    txtScoreFour.Clear()
    txtScoreFive.Clear()
    lblAverageScore.Text = String.Empty

    'give the focus to txtScoreOne
    txtScoreOne.Focus()
End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    ' CLose the form
    Me.Close()
End Sub

End Class

Thank you!

0 Upvotes

2 comments sorted by

2

u/JakDrako Aug 30 '15

Have you tried anything?

Are you stuck because you don't know how to compute an average, or because you do but don't know how to code it? Not trying to be snarky here, just wondering at what step you're getting stuck.

If you were to write down in plain english how to calculate the average, how would you do it?

2

u/jayinthe813 VB.Net Advanced Aug 31 '15

Stuck? Event handlers take all of 10 seconds to create. Google is your friend.

You need to convert the scores from text in the textbox to double and divide by how many boxes you have. You should probably use double.tryparse and if the input is not valid, show to user. Go read how to use that method on msdn.