-
Dec 12th, 2013, 07:49 PM
#1
Thread Starter
New Member
Different Grade Book Program
Hey, Have anotehr question about a different code. On this code I keep getting 'Items' is not a member of 'GradeBook.lstGrades'.
Public Class lstGrades
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim studentNames(4) As String
Dim Grades(4) As String
Dim Student1Scores(3) As Integer
Dim Student2Scores(3) As Integer
Dim Student3Scores(3) As Integer
Dim Student4Scores(3) As Integer
Dim Student5Scores(3) As Integer
Dim intCount As Integer = 0
Dim StudentAVG(4) As Double
lstGrades.Items.Clear()
Try
studentNames(0) = txtStudent1.Text
studentNames(1) = txtStudent2.Text
studentNames(2) = txtStudent3.Text
studentNames(3) = txtStudent4.Text
studentNames(4) = txtStudent5.Text
Student1Scores(0) = IsValid(CInt(txtOneScore1.Text))
Student1Scores(1) = IsValid(CInt(txtOneScore2.Text))
Student1Scores(2) = IsValid(CInt(txtOneScore3.Text))
Student1Scores(3) = IsValid(CInt(txtOneScore4.Text))
Student2Scores(0) = IsValid(CInt(txtTwoScore1.Text))
Student2Scores(1) = IsValid(CInt(txtTwoScore2.Text))
Student2Scores(2) = IsValid(CInt(txtTwoScore3.Text))
Student2Scores(3) = IsValid(CInt(txtTwoScore4.Text))
Student3Scores(0) = IsValid(CInt(txtThreeScore1.Text))
Student3Scores(1) = IsValid(CInt(txtThreeScore2.Text))
Student3Scores(2) = IsValid(CInt(txtThreeScore3.Text))
Student3Scores(3) = IsValid(CInt(txtThreeScore4.Text))
Student4Scores(0) = IsValid(CInt(txtFourScore1.Text))
Student4Scores(1) = IsValid(CInt(txtFourScore2.Text))
Student4Scores(2) = IsValid(CInt(txtFourScore3.Text))
Student4Scores(3) = IsValid(CInt(txtFourScore4.Text))
Student5Scores(0) = IsValid(CInt(txtFiveScore1.Text))
Student5Scores(1) = IsValid(CInt(txtFiveScore2.Text))
Student5Scores(2) = IsValid(CInt(txtFiveScore3.Text))
Student5Scores(3) = IsValid(CInt(txtFiveScore4.Text))
StudentAVG(0) = getAverage(Student1Scores)
StudentAVG(1) = getAverage(Student2Scores)
StudentAVG(2) = getAverage(Student3Scores)
StudentAVG(3) = getAverage(Student4Scores)
StudentAVG(4) = getAverage(Student5Scores)
For intCount = 0 To 4
If StudentAVG(intCount) >= 90 Then
Grades(intCount) = "A"
ElseIf StudentAVG(intCount) >= 80 Then
Grades(intCount) = "B"
ElseIf StudentAVG(intCount) >= 70 Then
Grades(intCount) = "C"
ElseIf StudentAVG(intCount) >= 60 Then
Grades(intCount) = "D"
ElseIf StudentAVG(intCount) > 0 Then
Grades(intCount) = "F"
End If
Next
For intCount = 0 To 4
lstGrades.Items.Add(" Average Score for " & studentNames(intCount) & " is " & StudentAVG(intCount) & " his Grade is " & Grades(intCount))
Next
Catch
MessageBox.Show("Invalid Input: Enter Values between(0-100)", "Error")
End Try
End Sub
Public Function getAverage(ByVal StudentScores() As Integer)
Dim intTotal, intCount As Integer
Dim dblAverage As Double
For intCount = 0 To 3
intTotal += StudentScores(intCount)
Next
dblAverage = intTotal / 4
Return dblAverage
End Function
Public Function IsValid(ByVal intNum As Integer)
If intNum > 0 And intNum <= 100 Then
Return intNum
Else
Return "Error"
End If
End Function
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub txtStudent1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStudent1.TextChanged
End Sub
Private Sub btnClear_Click_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtStudent1.Clear()
txtStudent2.Clear()
txtStudent3.Clear()
txtStudent4.Clear()
txtStudent5.Clear()
txtOneScore1.Clear()
txtOneScore2.Clear()
txtOneScore3.Clear()
txtOneScore4.Clear()
txtTwoScore1.Clear()
txtTwoScore2.Clear()
txtTwoScore3.Clear()
txtTwoScore4.Clear()
txtThreeScore1.Clear()
txtThreeScore2.Clear()
txtThreeScore3.Clear()
txtThreeScore4.Clear()
txtFourScore1.Clear()
txtFourScore2.Clear()
txtFourScore3.Clear()
txtFourScore4.Clear()
txtFiveScore1.Clear()
txtFiveScore2.Clear()
txtFiveScore3.Clear()
txtFiveScore4.Clear()
lstGrades.Items.Clear()
End Sub
End Class
-
Dec 12th, 2013, 08:40 PM
#2
Re: Different Grade Book Program
Um, yeah... that's because it isn't. Do you maybe have a ListBox named 'lstGrades'? If so then it would make sense not to name the class defined in that code you posted 'lstGrades' as well, because it's that class that you're referring to when you use that name and that class has no Items property.
By the way, please use code formatting tags when posting code because it's much more readable that way. The harder you make it for us to help you, the less likely you are to get the help you want.
-
Dec 12th, 2013, 08:52 PM
#3
Thread Starter
New Member
Re: Different Grade Book Program
I apologize, I will in the future. I was in a rush and Thank you for your post.
-
Dec 12th, 2013, 09:54 PM
#4
Re: Different Grade Book Program
How is this a different program? It sure looks similar. You're even back to using IsValid(CInt()) which has the same problems that it did in the previous program. Of course, this time you are returning nothing from the IsValid function, which shouldn't even compile, but if it did it would be returning type Object, which is pretty much a disaster, in this case, because it could be either a string or an integer, one of which will throw an exception while the other will not.
My usual boring signature: Nothing
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
|