Option Explicit On
Option Strict On
Option Infer Off
Public Class Form1
Private currentSemesCoursePoints As ArrayList
Private currentSemesCourseHours As ArrayList
Private totalSemesterPoints As Double
Private totalSemesterHours As Double
' This sub is what loads to the form when the application is run.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' These set the 2 declared private variables to a capacity of (5)
currentSemesCoursePoints = New ArrayList(5)
currentSemesCourseHours = New ArrayList(5)
' This load section will load the grades in the grade comboBox
gradeComboBox.Items.Add("A")
gradeComboBox.Items.Add("AB")
gradeComboBox.Items.Add("B")
gradeComboBox.Items.Add("BC")
gradeComboBox.Items.Add("C")
gradeComboBox.Items.Add("D")
gradeComboBox.Items.Add("F")
gradeComboBox.SelectedIndex = 0
End Sub
' This sub adds items that are entered (course name, credit hours, and grade) to the list box
Private Sub addToListButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addToListButton.Click
' Declare the variables used in the addtolistbutton.click event
Dim creditHours As Integer
Dim arrayListValidation As Boolean
Dim hoursString As Integer
arrayListValidation = checkCourseLimit()
creditHours = validateHours(hoursString)
If creditHours > 0 Then
processList(creditHours)
Else
MessageBox.Show("Entered value was not numeric.")
End If
End Sub
' This function checks to see if the entered values are numeric
Private Function validateHours(ByVal hoursString As Integer) As Integer
Dim validData As Boolean
Dim hours As Integer
validData = Integer.TryParse(creditHoursTxtBox.Text, hoursString)
Integer.TryParse(creditHoursTxtBox.Text, hours)
If validData = False Then
MessageBox.Show("Entered credit hours was not numeric")
Else
hours = validateHoursRange()
End If
Return hours
End Function
' This function checks to see if the entered values are between 1-5
Private Function validateHoursRange() As Integer
Dim hours As Integer
Integer.TryParse(creditHoursTxtBox.Text, hours)
If hours < 1 OrElse hours > 5 Then
MessageBox.Show("Values entered must be between 1-5")
creditHoursTxtBox.Focus()
creditHoursTxtBox.SelectAll()
End If
Return hours
End Function
' This function checks to see if the course limit of 5 has been reached.
Private Function checkCourseLimit() As Boolean
Dim arrayListValidation As Boolean
' If statement to check to see if the max capacity for classes was reached
If currentSemesCourseHours.Count = currentSemesCourseHours.Capacity Then
MessageBox.Show("Max capacity for classes has been reached.")
End If
Return arrayListValidation
End Function
Private Function determineNumberOfPoint(ByVal grade As String) As Double
Dim recieveLetterGrade As Double
If grade = "A" Then
recieveLetterGrade = 4.0
ElseIf grade = "AB" Then
recieveLetterGrade = 3.5
ElseIf grade = "B" Then
recieveLetterGrade = 3.0
ElseIf grade = "BC" Then
recieveLetterGrade = 2.5
ElseIf grade = "C" Then
recieveLetterGrade = 2.0
ElseIf grade = "D" Then
recieveLetterGrade = 1.0
Else
recieveLetterGrade = 0
End If
Return recieveLetterGrade
End Function
' This sub removes items in the list box from both array lists
Private Sub removeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles removeButton.Click
Dim index As Integer
' setting what was selected in the listbox and setting it to the variable index
index = listBoxOutput.SelectedIndex
If index = -1 Then
MessageBox.Show("You must select an item to remove!", "Selected Item",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
listBoxOutput.Items.RemoveAt(index)
currentSemesCourseHours.RemoveAt(index)
currentSemesCoursePoints.RemoveAt(index)
End If
End Sub
Private Sub processList(ByVal creditHours As Integer)
' Declare Variables
Dim courseName As String
Dim grade As String
Dim numberOfPoints As Double
courseName = txtCourseName.Text
grade = Convert.ToString(gradeComboBox.SelectedItem)
numberOfPoints = creditHours * determineNumberOfPoint(grade)
listBoxOutput.Items.Add(courseName & ", " & creditHours & " Credit Hour(s), " & grade)
currentSemesCourseHours.Add(creditHours)
currentSemesCoursePoints.Add(grade)
End Sub
' This is the exit sub, when the exit button is clicked it will close the program.
Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
' This will close the application when clicked
Me.Close()
End Sub
Private Sub calcNewGPAButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcNewGPAButton.Click
' Declare Variables
'Dim totalCredithours As Integer
'Dim newCurrentHours As Integer
'Dim priorHours As Integer
'Dim loopIndex As Integer
'Dim totalGradePoints As Double
Dim semesterGPA As Double
Dim newCumulativeGPA As Double
'Dim newPoints As Double
'Dim priorPoints As Double
'Dim priorGPA As Double
calculateSemesterGPA(semesterGPA)
processCumulativeGPA(newCumulativeGPA)
lblSemesterGPAOutput.Text = semesterGPA.ToString("N2")
lblCumulativeGPAOutput.Text = newCumulativeGPA.ToString("N2")
End Sub
Private Function processCumulativeGPA(ByVal newCumulativeGPA As Double) As Double
Dim priorGPA As Double
Dim priorHours As Integer
Dim newCumulativePoints As Double
Dim newCumulativeHours As Double
Dim cumulativeGPA As Double
Double.TryParse(priorGPATxtBox.Text, priorGPA)
Integer.TryParse(priorCreditHoursTxtBox.Text, priorHours)
newCumulativePoints = (priorGPA * priorHours) + totalSemesterPoints
newCumulativeHours = priorHours + totalSemesterHours
If newCumulativeHours > 0 Then
cumulativeGPA = totalSemesterPoints / totalSemesterHours
End If
Return newCumulativeGPA
End Function
Private Function calculateSemesterGPA(ByVal semesterGPA As Double) As Double
'Declare Variables
Dim gpa As Double
Dim index As Integer
Dim index1 As Integer
For index = 0 To currentSemesCourseHours.Count - 1
totalSemesterHours += currentSemesCourseHours.Count
For index1 = 0 To currentSemesCoursePoints.Count - 1
totalSemesterPoints += currentSemesCoursePoints.Count
Next
Next
If totalSemesterHours > 0 Then
semesterGPA = totalSemesterPoints / totalSemesterHours
End If
Return gpa
End Function
End Class
need help with my outputs and calculations
Page 1 of 13 Replies - 231 Views - Last Post: 07 July 2011 - 05:33 PM
#1
need help with my outputs and calculations
Posted 07 July 2011 - 12:24 PM
So this has been bothering and frustrating the H outta me for the past week, I'm having trouble with getting my listbox to only accept 5 entries and anything more than that shouldn't work...I'm also having trouble with getting my output to work for the newcumulativeGPA label and the newsemesterGPA label. As you can see in my coding I am a beginner and i'm sure there are more things wrong with this code, arrays are hard for me to understand and passing information between functions is also giving me a hard time. any help would be appreciated. thank you. this website is awesome by the way, I'm glad I stumbled upon it 
Replies To: need help with my outputs and calculations
#2
Re: need help with my outputs and calculations
Posted 07 July 2011 - 02:18 PM
Private Function checkCourseLimit() As Boolean
Dim arrayListValidation As Boolean
' If statement to check to see if the max capacity for classes was reached
If currentSemesCourseHours.Count = currentSemesCourseHours.Capacity Then
MessageBox.Show("Max capacity for classes has been reached.")
End If
Return arrayListValidation
End Function
You never set the value of arrayListValidation from its default of false. Then you never use the value returned by this function in addToListButton_Click. So OF COURSE you're not preventing more than five entries from being added!
Unless you're using .NET 1.1, there's no good reason to use ArrayLists when you've got generic Lists available to you.
#3
Re: need help with my outputs and calculations
Posted 07 July 2011 - 04:48 PM
I tried that and still adds to the list. I get the pop us saying that my max has been reached but then after i close the messegeBox it adds it anyway...
#4
Re: need help with my outputs and calculations
Posted 07 July 2011 - 05:33 PM
Can you post your updated code please
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|