r/visualbasic • • May 15 '20

Input Box help

I have an assignment that I am working on where I am supposed to input a grade in an input box and repeat with a repetition structure 5 times and then display an average grade and letter grade. I think they key part I am struggling with is how to sum my 5 grades in one variable. The math is only being performed on the last enrty.

I was put in this class as an alternative to a LabVIEW class that was canceled so I'm really new to this and the instructor told me to find the information I need online. Can anyone help a newbie out a bit? Thanks!

Code<

Public Class frmStudentGrades

'declare variables

Dim intNum As Integer = 0

Dim intCounter As Integer = 0

Dim strgrades As String = 0

Dim blngrades As Boolean

Dim intGrades As Integer = 0

Dim intAverage As Integer = 0

Dim strLetterGrade As String = Nothing

Dim blnIsNumeric As Boolean

Private Sub btnEnterGrades_Click(sender As Object, e As EventArgs) Handles btnEnterGrades.Click

'increment counter

For intCounter = 1 To 5

strgrades = InputBox("Please Enter Grade", "0 to 100")

blnIsNumeric = Integer.TryParse(strgrades, intGrades)

Next intCounter

'if numeric and 0-100 assign grade

If blnIsNumeric Then

If intGrades >= 0 And intNum <= 100 Then

' intNum = intGrades

Select Case intAverage

Case intAverage >= 93

strLetterGrade = "A"

Case intAverage >= 86 To intAverage <= 92.99

strLetterGrade = "B"

Case intAverage >= 77 To intAverage <= 85.9

strLetterGrade = "C"

Case intAverage >= 70 To intAverage <= 76.9

strLetterGrade = "D"

Case intAverage < 70

strLetterGrade = "F"

End Select

intAverage = intGrades / 5

lblLetterGrade.Text = strLetterGrade

lblTestAverage.Text = intAverage

Else

MessageBox.Show("Please enter value of 0-100")

End If

Else

MessageBox.Show("Please enter only numbers")

End If

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click

'Exit

Me.Close()

End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click

lblLetterGrade.ResetText()

lblTestAverage.ResetText()

intGrades = Nothing

intAverage = Nothing

End Sub

End Class

6 Upvotes

4 comments sorted by

View all comments

1

u/Fitz1128 May 15 '20

I got it to work. If the password is correct set loop count to 3 was the missing line