Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Reference Not Set- collection issue 1

Status
Not open for further replies.

hitechboy78737

Programmer
Nov 8, 2004
82
US
I have an array list that exists in a class that I add to using the .add method.

ex.
.bonusColl.Add(objBonus)

I know that the objBonus is a valid object containing data.

When this line goes to retrieve the public property bonusColl, I get the "Object Reference" error.

I'm kinda lost here... it works fine in another class, and I can't seem to find what's different...

Here's some code:
Code:
Public Function getBonusCollFromTerms(ByVal termID As Long) As cls_BonusCollection
        Dim objConn As New OleDbConnection(getDSN())
        Dim strSQL As String = "SELECT fldBonID, fldTermID, fldBonAmt, fldBonCap, fldBonText, fldBonRcv FROM tblBonuses WHERE fldTermID= " & termID & " ORDER BY fldBonCap;"
        Dim ds As DataSet = getDataSet(objConn, strSQL, "tblBonuses", "text")
        Dim dt As DataTable = ds.Tables("tblBonuses")
        Dim rowCount As Integer = dt.Rows.Count
        Dim dr As DataRow
        Dim x As Integer = 0
        Try
            Dim objBonusCollection As New cls_BonusCollection
            objBonusCollection.clearBonusCollection()
            If rowCount > 0 Then
                Do While x < rowCount
                    dr = dt.Rows(x)
                    Dim objBonus As New cls_Bonus
                    With objBonus
                        .dataRow2objBonus(dr, objBonus)
                        add2BonusCollection(objBonusCollection, objBonus)
                    End With
                    x = x + 1
                Loop
            End If
            Return objBonusCollection
        Catch ex As Exception
            showError(ex)
        Finally
            objConn.Close()
            ds.Dispose()
            dt.Dispose()
        End Try
    End Function

which calls add2BonusCollection

Code:
 Public Sub add2BonusCollection(ByRef objBonusCollection As cls_BonusCollection, ByVal objBonus As cls_Bonus)
        Try
            With objBonusCollection
                'set collection variables
                .bonusCollTermID = objBonus.bonusTermID
                'calculate gross
                .calcBonusCollGross(objBonusCollection, objBonus, "+")
                'add bonus to collection
                .bonusColl.Add(objBonus)
                'update count
                .bonusCollCount = .bonusColl.Count
            End With
        Catch ex As Exception
            showError(ex)
        End Try
    End Sub

All the lines work except for .bonusColl.Add(objBonus) The public property looks like this:
Code:
 Public Property bonusColl() As ArrayList
        Get
            Return _bonusColl
        End Get
        Set(ByVal Value As ArrayList)
            _bonusColl = Value
        End Set
    End Property

Again, I know that the objBonus has data, the objBonusCollection is good... its just when I get the public property bonusColl from the objBonusCollection that I get this error.

If I need to include some more of the code- please tell me.. I guessed what would be useful

Thanks for your help... I'm really symied on this one but it will turn out to be something really simple I bet!

Kevin Howell
Briefcase of Talent- Austin, Tx
 
do you have this in the cls_bonuscollection?

dim _bonusColl as new arraylist

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Well heck... I'm an idiot.. or at least so heads down in the mass of code I've generated that I cant see the forest for the declarations... I actually did not have the "new" keyword where I declared _bonusColl! I THOUGHT I did.. but it was declared as new in the calling procedure... NOT in the main class! I thought I was loosing my mind... or that something was wrong... but of course it always comes back to ID-10-T error....

See, I knew it would be something maddenly simple...

Once again... Christiaan saved my bacon!

Thanks man! Here's a cookie for you and your dog!

Kevin
 
I THOUGHT I did

Famous last words.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top