Object reference not set to an instance of an object

RudeYute

Member
Joined
Dec 15, 2004
Messages
6
Programming Experience
Beginner
I have a form which allows you to select the records. What I'm trying to do is be able to click a button which opens another form, and displays some parts of the selected record.

I have tried the following code in the Form_Load event and the Form_Activated event, but wherever I put it, I get the object reference error on load of the form.

VB.NET:
Dim ds As New DataSet 

        ds = basVehicles.getVehicles

        Try
            lblBuyMake.Text = ds.Tables(0).Rows(0).Item("Make").ToString
            lblBuyModel.Text = ds.Tables(0).Rows(0).Item("Model").ToString
            lblBuyPrice.Text = ds.Tables(0).Rows(0).Item("Price").ToString
            'pbVehicleImage.Text = ds.Tables(0).Rows(0).Item("Picture").ToString
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
The only thing I thought it could be was the declaration, but can't see what's wrong with it.

Someone help please,

Thanks
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,543
Location
Norway
Programming Experience
10+
Is this line "ds = basVehicles.getVehicles" you get object error on?
If so, what is "basVehicles" (in this context) ?
 

RudeYute

Member
Joined
Dec 15, 2004
Messages
6
Programming Experience
Beginner
I'm not sure - It don't seem to highlight the problem when debugging.
BasVehicles is a reference file which I have used. contents below:

Module basVehicles
Private mVehicles As DataSet
Public Property getVehicles() As DataSet
Get
getVehicles = mVehicles
End Get
Set(ByVal Value as DataSet)
mVehicles = Value
End Set
End Property

End Module
 

m_ogden

Well-known member
Joined
Mar 3, 2006
Messages
74
Location
New Hampshire
Programming Experience
5-10
in your basVehicles module, you need to create the instance of the dataset there... so your code should read:
VB.NET:
dim ds as DataSet
Set ds = basVehicles.getVehicles
then in your basVehicles module, it should read:
VB.NET:
'... property declaration and previous code...
Get
if isnothing(mVehicles) then
mVehicles = new DataSet
end if
return mVehicles
End Get
'... remaining code...'
also if you don't intend on making that getVehicles property writeable, you might as well mark it readonly and remove the Set statement, i.e.
VB.NET:
Public ReadOnly Property getVehicles() as DataSet
 

RudeYute

Member
Joined
Dec 15, 2004
Messages
6
Programming Experience
Beginner
Hi,

This is now sorted. Had someone more experienced than myself look at it.
Turns out a few things were wrong, so lucky I got it checked over.

Thanks for all your help.
 
Top Bottom