trying to get streamreader to read and my calculations to populate my textbox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: trying to get streamreader to read and my calculations to populate my textbox

  1. #1
    Join Date
    Jul 2013
    Posts
    5

    trying to get streamreader to read and my calculations to populate my textbox

    Here what i have so far, the error in the stream
    [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[\CODE]

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,266

    Re: trying to get streamreader to read and my calculations to populate my textbox

    This isn't c++ code! I think you have posted to the wrong forum. Try one of the visual basic forums.

    [moderator would you please move]
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center