Hey everyone i have some code here that bring in one line text from a file and displays into labels. I want to add up eight values from labels and divide by 8 to get the average, and convert that average score into a letter grade that will be displayed in a new label. The code i need help with is in the btnCal procedural.
Here is my code:
Imports System.IO
Public Class Form1
Dim grade As String
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
OFDG1.Filter = "Text Files|*.txt|All Files|*.*"
Dim myResult As DialogResult
myResult = OFDG1.ShowDialog
If myResult = Windows.Forms.DialogResult.OK Then
Dim strReader As StreamReader = File.OpenText(OFDG1.FileName)
Dim aline As String
Do Until strReader.EndOfStream
aline = strReader.ReadLine
Dim myStuff() = aline.Split(","c)
lblStudent.Text = myStuff(0)
lblClassField.Text = myStuff(1)
lblSemesterInput.Text = myStuff(2)
picStudent.Image = Image.FromFile(myStuff(3))
lblInput1.Text = myStuff(4)
lblInput2.Text = myStuff(5)
lblInput3.Text = myStuff(6)
lblInput4.Text = myStuff(7)
lblInput5.Text = myStuff(8)
lblInput6.Text = myStuff(9)
lblMidtermInput.Text = myStuff(10)
lblFinalInput.Text = myStuff(11)
Loop
strReader.Close()
Else
MessageBox.Show("You clicked other than OK")
End If
End Sub
Private Sub btnCal_Click(sender As Object, e As EventArgs) Handles btnCal.Click
grade = CStr(CInt(lblInput1.Text + lblInput2.Text + lblInput3.Text _
+ lblInput4.Text + lblInput5.Text + _
lblInput6.Text + lblMidtermInput.Text + lblFinalInput.Text / 8)
lblFinalLetterGrade.Text = Calculation(CInt(grade))
End Sub
Public Function Calculation(ByVal grade As Integer) As String
Select Case grade
Case Is > 89
Return "A"
Case Is > 79
Return "B"
Case Is > 69
Return "C"
Case Is > 59
Return "D"
Case Else
Return "F"
End Select
End Function
End Class