Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Trying to get streamreader to readfile and textbox to populate calculations

$
0
0
this is the code i have, im having trouble getting my stream reader to load and my answer to populate the textbox

Code:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim fileName As String = IO.File.ReadAllText("Grades.txt")
        Dim GPA As Double = 0
        Dim i As Integer = 0
        If IO.File.Exists(fileName) Then
            Dim sr As New IO.StreamReader(fileName)
            Dim line As String
            Dim finalscore As Double = 0
            Dim count As Integer = 0

            Using reader As = StreamReader = New StreamReader(fileName)
                While Not reader.EndOfStream

                End While

                line = reader.ReadLine()
            End Using



            If line.Trim() <> String.Empty Then
                finalscore += calculate(line)
                count += 1
            End If

            GPA = finalscore / (count * 3)
            TextBox1.Text = "student's GPa is " & Math.Round(GPA, 2).ToString()


        End If



    End Sub

    Private Function calculate(ByVal grade As String) As Double
        Dim value As Double = 0

        If grade = "A" Then
            value = 4.0 * 3

        ElseIf grade = "A-" Then
            value = 3.67 * 3

        ElseIf grade = "B+" Then
            value = 3.33 * 3

        ElseIf grade = "B" Then
            value = 3 * 3

        ElseIf grade = "B-" Then
            value = 2.67 * 3

        ElseIf grade = "C+" Then
            value = 2.33 * 3

        ElseIf grade = "C" Then
            value = 2.0 * 3

        ElseIf grade = "C-" Then
            value = 1.67 * 3

        ElseIf grade = "D" Then
            value = 1.0 * 3

        ElseIf grade = "F" Then
            value = 0

        End If

        Return value


    End Function
End Class


Viewing all articles
Browse latest Browse all 27554

Trending Articles