Hi,
I am trying to build a class that works with a form, but I keep getting the dreaded "Object reference not set to an instance of an object" Error.
The form basically collects test grades and assigns them to a collection.
My class code is as follows:
My form code is:Code:Public Class Scores Private colScoreCollection As New Collection Public mintSum As Integer Public mdecAverage As Decimal Public mintMinimum As Integer Public mintMaximum As Integer Public mintNumberOfScores As Integer Public Sub New() colScoreCollection = Nothing mintSum = 0 mdecAverage = 0 mintMinimum = 0 mintMaximum = 0 mintNumberOfScores = 0 End Sub Public ReadOnly Property Sum() As Integer Get Return mintSum End Get End Property Public ReadOnly Property Average() As Decimal Get Return mdecAverage End Get End Property Public ReadOnly Property Minimum() As Integer Get Return mintMinimum End Get End Property Public ReadOnly Property Maximum() As Integer Get Return mintMaximum End Get End Property Public ReadOnly Property NumberOfScores() As Integer Get Return mintNumberOfScores End Get End Property Public Sub AddScore(ByVal intGrades As Integer) colScoreCollection.Add(intGrades) End Sub End Class
I had a similar project I was working on that had a collection in it, but now that one is giving me the same error. It there something with my version of Visual Studio that is causing this error possibly?Code:Imports TestScores Public Class Form1 Inherits System.Windows.Forms.Form Private Sub btnAddScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddScore.Click Dim intGrade As Integer intGrade = Convert.ToInt32(nudScores.Value) gobjScores.AddScore(intGrade) End Sub End Class
Thanks for any help.




Reply With Quote