|
-
Mar 27th, 2013, 02:34 PM
#1
Thread Starter
Junior Member
GPA calculator textbox issues
I have programmed a GPA calculator to where their are 8 textboxes to enter the course names, 8 textboxes for the number of hours each course is worth, and lastly 8 textboxes for the letter grade you made in those courses. I am having trouble with the 8 textboxes that take the credit hours. If I don't feel each one in with a number it gives me the error "Input String was not in correct format". I wanted to program it to where if the user is only taking 5 classes they can leave the other 3 textboxes blank and a "0" will be put in the textboxes they did not fill in for the credit hours, and just calculate the GPA from the 5 classes entered. It work correctly if the user inputs into all 8 textboxes for credit hours but, that error code I mentioned above comes up if they don't fill in all 8....
Here is the code I have so far.
Code:
Public Class Form1
Dim QualityPoints As Double
Dim CourseName, hours As String
Private Sub btnTotalHours_Click(sender As Object, e As EventArgs) Handles btnTotalHours.Click
Dim totalHours As String
Dim Credit1, Credit2, Credit3, Credit4, Credit5, Credit6, Credit7, Credit8 As Integer
Credit1 = Integer.Parse(txtBoxCredit1.Text)
Credit2 = Integer.Parse(txtBoxCredit2.Text)
Credit3 = Integer.Parse(txtBoxCredit3.Text)
Credit4 = Integer.Parse(txtBoxCredit4.Text)
Credit5 = Integer.Parse(txtBoxCredit5.Text)
Credit6 = Integer.Parse(txtBoxCredit6.Text)
Credit7 = Integer.Parse(txtBoxCredit7.Text)
Credit8 = Integer.Parse(txtBoxCredit8.Text)
totalHours = CStr(txtBoxTotalHours.Text)
txtBoxTotalHours.Text = (Credit1 + Credit2 + Credit3 + Credit4 + Credit5 + Credit6 + Credit7 + Credit8)
End Sub
Private Sub btnTotalQualityPoints_Click(sender As Object, e As EventArgs) Handles btnTotalQualityPoints.Click
Select Case txtBoxGrade1.Text
Case "A"
QualityPoints += (4 * txtBoxCredit1.Text)
Case "B"
QualityPoints += (3 * txtBoxCredit1.Text)
Case "C"
QualityPoints += (2 * txtBoxCredit1.Text)
Case "D"
QualityPoints += (1 * txtBoxCredit1.Text)
Case "F"
QualityPoints += (0 * txtBoxCredit1.Text)
Case " "
QualityPoints += (0 * txtBoxCredit1.Text)
End Select
Select Case txtBoxGrade2.Text
Case "A"
QualityPoints += (4 * txtBoxCredit2.Text)
Case "B"
QualityPoints += (3 * txtBoxCredit2.Text)
Case "C"
QualityPoints += (2 * txtBoxCredit2.Text)
Case "D"
QualityPoints += (1 * txtBoxCredit2.Text)
Case "F"
QualityPoints += (0 * txtBoxCredit2.Text)
Case " "
QualityPoints += (0 * txtBoxCredit2.Text)
End Select
Select Case txtBoxGrade3.Text
Case "A"
QualityPoints += (4 * txtBoxCredit3.Text)
Case "B"
QualityPoints += (3 * txtBoxCredit3.Text)
Case "C"
QualityPoints += (2 * txtBoxCredit3.Text)
Case "D"
QualityPoints += (1 * txtBoxCredit3.Text)
Case "F"
QualityPoints += (0 * txtBoxCredit3.Text)
Case " "
QualityPoints += (0 * txtBoxCredit3.Text)
End Select
Select Case txtBoxGrade4.Text
Case "A"
QualityPoints += (4 * txtBoxCredit4.Text)
Case "B"
QualityPoints += (3 * txtBoxCredit4.Text)
Case "C"
QualityPoints += (2 * txtBoxCredit4.Text)
Case "D"
QualityPoints += (1 * txtBoxCredit4.Text)
Case "F"
QualityPoints += (0 * txtBoxCredit4.Text)
Case " "
QualityPoints += (0 * txtBoxCredit4.Text)
End Select
Select Case txtBoxGrade5.Text
Case "A"
QualityPoints += (4 * txtBoxCredit5.Text)
Case "B"
QualityPoints += (3 * txtBoxCredit5.Text)
Case "C"
QualityPoints += (2 * txtBoxCredit5.Text)
Case "D"
QualityPoints += (1 * txtBoxCredit5.Text)
Case "F"
QualityPoints += (0 * txtBoxCredit5.Text)
Case " "
QualityPoints += (0 * txtBoxCredit5.Text)
End Select
Select Case txtBoxGrade6.Text
Case "A"
QualityPoints += (4 * txtBoxCredit6.Text)
Case "B"
QualityPoints += (3 * txtBoxCredit6.Text)
Case "C"
QualityPoints += (2 * txtBoxCredit6.Text)
Case "D"
QualityPoints += (1 * txtBoxCredit6.Text)
Case "F"
QualityPoints += (0 * txtBoxCredit6.Text)
Case " "
QualityPoints += (0 * txtBoxCredit6.Text)
End Select
Select Case txtBoxGrade7.Text
Case "A"
QualityPoints += (4 * txtBoxCredit7.Text)
Case "B"
QualityPoints += (3 * txtBoxCredit7.Text)
Case "C"
QualityPoints += (2 * txtBoxCredit7.Text)
Case "D"
QualityPoints += (1 * txtBoxCredit7.Text)
Case "F"
QualityPoints += (0 * txtBoxCredit7.Text)
Case " "
QualityPoints += (0 * txtBoxCredit7.Text)
End Select
Select Case txtBoxGrade8.Text
Case "A"
QualityPoints += (4 * txtBoxCredit8.Text)
Case "B"
QualityPoints += (3 * txtBoxCredit8.Text)
Case "C"
QualityPoints += (2 * txtBoxCredit8.Text)
Case "D"
QualityPoints += (1 * txtBoxCredit8.Text)
Case "F"
QualityPoints += (0 * txtBoxCredit8.Text)
Case " "
QualityPoints += (0 * txtBoxCredit8.Text)
End Select
txtBoxTotalQualityPoints.Text = QualityPoints
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtBoxCourse1.Clear()
txtBoxCourse2.Clear()
txtBoxCourse3.Clear()
txtBoxCourse4.Clear()
txtBoxCourse5.Clear()
txtBoxCourse6.Clear()
txtBoxCourse7.Clear()
txtBoxCourse8.Clear()
txtBoxCredit1.Clear()
txtBoxCredit2.Clear()
txtBoxCredit3.Clear()
txtBoxCredit4.Clear()
txtBoxCredit5.Clear()
txtBoxCredit6.Clear()
txtBoxCredit7.Clear()
txtBoxCredit8.Clear()
txtBoxGrade1.Clear()
txtBoxGrade2.Clear()
txtBoxGrade3.Clear()
txtBoxGrade4.Clear()
txtBoxGrade5.Clear()
txtBoxGrade6.Clear()
txtBoxGrade7.Clear()
txtBoxGrade8.Clear()
txtBoxTotalGPA.Clear()
txtBoxTotalHours.Clear()
txtBoxTotalQualityPoints.Clear()
End Sub
Thanks for any help that is provided!
-
Mar 27th, 2013, 02:49 PM
#2
Re: GPA calculator textbox issues
Why does everybody make this difficult for themselves? Use the NumericUpDown control for number entry. It doesn't need validating or conversion. It always returns a number and it should be obvious to the user that if they haven't got anything to enter it should remain at 0.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Tags for this Thread
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
|