473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating an object with methods problem

!NoItAll
297 100+
Ok - stuck on something I clearly don't understand well....

In the code below (which I just wrote here - it closely mirrors what my actual code is...) the problem is with the line:

Thing.ThingObject.Add(MyObject)

It says: "Object reference not set to an instance of an object"

Yes - it is "nothing" before I try to use the Add method so I must be doing something basic and wrong.
The object I am trying to add is fine - I can tell you it is correct, it's just that I apparently cannot use the .add method on the Thing.ThingObject until it is properly created - which I have apparently not done.
I'm hoping this is just a syntactical thing.....

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub DoThing()
  3.  
  4.       Dim MyObject as New Object
  5.  
  6.       MyObject = MakeMyObject
  7.  
  8.       Dim Thing as New ListOfThings
  9.  
  10.       Thing.ThingObject.Add(MyObject)
  11.  
  12. End Sub
  13.  
  14. Partial Public Class ListOfThings
  15.    Inherits Object
  16.    Private vThingObject as ArrayOfThings
  17.  
  18.    Public Property ThingObject as ArrayOfThings
  19.  
  20.        Get
  21.            return vThingObject
  22.        End Get
  23.        Set
  24.             vThingObject = Value
  25.        End Set
  26.    End Property
  27.  
  28. End Class
  29.  
  30. Public Class ArrayOfThings
  31.      Inherits System.Collections.Generic.List(of Objects)
  32. End Class
  33.  
  34.  
Mar 25 '10 #1

✓ answered by phvfl

Hi,

You are creating an instance of the ListOfThings class - but the member vThingObject is not having an instance created. i.e. Thing is not nothing but Thing.ThingObject is nothing.

Assuming that ArrayOfThings has a parameterless constructor add the following to the ListOfThings class:
Expand|Select|Wrap|Line Numbers
  1. Public Sub New()
  2.  vThingObject = New ArrayOfThings()
  3. End Sub
  4.  

2 963
phvfl
173 Expert 100+
Hi,

You are creating an instance of the ListOfThings class - but the member vThingObject is not having an instance created. i.e. Thing is not nothing but Thing.ThingObject is nothing.

Assuming that ArrayOfThings has a parameterless constructor add the following to the ListOfThings class:
Expand|Select|Wrap|Line Numbers
  1. Public Sub New()
  2.  vThingObject = New ArrayOfThings()
  3. End Sub
  4.  
Mar 25 '10 #2
!NoItAll
297 100+
Yup - that was it. I found that, for simplicity, all I needed to do was to declare the private variable within the class with the NEW constructor.
Thanks phvfl!
Mar 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Piro | last post by:
I have a class that I want to make accessible to a web service. This class does some work in its constructor method and sets some class variables in its various methods. The problem I am having...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
1
by: CES | last post by:
All, I was wondering if someone could point me to a tutorial on creating & accessing functions from within a wrapper function. I've created a group of functions related to a timer event. All...
16
by: tshad | last post by:
This is a little complicated to explain but I have some web services on a machine that work great. The problem is that I have run into a situation where I need to set up my program to access one...
1
by: Kev | last post by:
Gidday, I am stuck trying to create a COM Callable Wrapper for the class (shell only) below. As you can see I have tried to define my interface and it would be all good if I wasn't passing my...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
5
by: Dan | last post by:
Hi, I use the <asp:CreateUserWizardcontrol for creating memberusers. In that windows, one must provide an emailaddress. My question is: how can an user later change his emailaddress? Thanks...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
3
by: Bartholomew Simpson | last post by:
I am writing some C++ wrappers around some legacy C ones - more specifically, I am providing ctors, dtors and assignment operators for the C structs. I have a ton of existing C code that uses...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.