-
July 27th, 2013, 11:15 AM
#1
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]
-
July 27th, 2013, 11:49 AM
#2
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|