Storing Objects in a Hashtable 
Author Message
 Storing Objects in a Hashtable

Is it possible to store objects in a hashtable?  Here's what I am trying to
do:

dim h1 as HashTable
h1.Add("P1", New Parameter(Name,Value))

In this case Parameter is a class and I am trying to create a new instance
of a parameter and store it in the Hashtable.  Thanks for any help.

- Joe



Tue, 13 Jul 2004 05:39:45 GMT  
 Storing Objects in a Hashtable
That looks like it should work fine.. are you getting an error?


Quote:
> Is it possible to store objects in a hashtable?  Here's what I am trying
to
> do:

> dim h1 as HashTable
> h1.Add("P1", New Parameter(Name,Value))

> In this case Parameter is a class and I am trying to create a new instance
> of a parameter and store it in the Hashtable.  Thanks for any help.

> - Joe



Tue, 13 Jul 2004 05:45:49 GMT  
 Storing Objects in a Hashtable
Yes I get an error: Value null was found where an instance of an object was
required.
Which looks to me like the object doesn't get created, but I tried testing
for that and it appeared to get created.  I created a local object and set
it equal to the new parameter first, then used the local object in the
hashtable.add and that failed too.

- Joe


Quote:
> That looks like it should work fine.. are you getting an error?



> > Is it possible to store objects in a hashtable?  Here's what I am trying
> to
> > do:

> > dim h1 as HashTable
> > h1.Add("P1", New Parameter(Name,Value))

> > In this case Parameter is a class and I am trying to create a new
instance
> > of a parameter and store it in the Hashtable.  Thanks for any help.

> > - Joe



Tue, 13 Jul 2004 06:01:17 GMT  
 Storing Objects in a Hashtable
I see whats wrong hehe :)

Dim H1 as new Hashtable


Quote:
> Yes I get an error: Value null was found where an instance of an object
was
> required.
> Which looks to me like the object doesn't get created, but I tried testing
> for that and it appeared to get created.  I created a local object and set
> it equal to the new parameter first, then used the local object in the
> hashtable.add and that failed too.

> - Joe



> > That looks like it should work fine.. are you getting an error?



> > > Is it possible to store objects in a hashtable?  Here's what I am
trying
> > to
> > > do:

> > > dim h1 as HashTable
> > > h1.Add("P1", New Parameter(Name,Value))

> > > In this case Parameter is a class and I am trying to create a new
> instance
> > > of a parameter and store it in the Hashtable.  Thanks for any help.

> > > - Joe



Tue, 13 Jul 2004 06:07:00 GMT  
 Storing Objects in a Hashtable
Your code says:

dim h1 as HashTable
h1.Add("P1", New Parameter(Name,Value))

which means h1 is still Null. Maybe you should write:

dim h1 as New HashTable
h1.Add("P1", New Parameter(Name,Value))


Quote:
> Yes I get an error: Value null was found where an instance of an object
was
> required.
> Which looks to me like the object doesn't get created, but I tried testing
> for that and it appeared to get created.  I created a local object and set
> it equal to the new parameter first, then used the local object in the
> hashtable.add and that failed too.

> - Joe



> > That looks like it should work fine.. are you getting an error?



> > > Is it possible to store objects in a hashtable?  Here's what I am
trying
> > to
> > > do:

> > > dim h1 as HashTable
> > > h1.Add("P1", New Parameter(Name,Value))

> > > In this case Parameter is a class and I am trying to create a new
> instance
> > > of a parameter and store it in the Hashtable.  Thanks for any help.

> > > - Joe



Tue, 13 Jul 2004 06:10:55 GMT  
 Storing Objects in a Hashtable
Do you ever set H1 = New HashTable()  ??

--
Jacob Grass
Microsoft .NET MVP


Quote:
> Yes I get an error: Value null was found where an instance of an object
was
> required.
> Which looks to me like the object doesn't get created, but I tried testing
> for that and it appeared to get created.  I created a local object and set
> it equal to the new parameter first, then used the local object in the
> hashtable.add and that failed too.

> - Joe



> > That looks like it should work fine.. are you getting an error?



> > > Is it possible to store objects in a hashtable?  Here's what I am
trying
> > to
> > > do:

> > > dim h1 as HashTable
> > > h1.Add("P1", New Parameter(Name,Value))

> > > In this case Parameter is a class and I am trying to create a new
> instance
> > > of a parameter and store it in the Hashtable.  Thanks for any help.

> > > - Joe



Tue, 13 Jul 2004 06:08:16 GMT  
 Storing Objects in a Hashtable
Did you forgot creating an instance of the HashTable ?
h1= new HashTable()


Quote:
> Yes I get an error: Value null was found where an instance of an object
was
> required.
> Which looks to me like the object doesn't get created, but I tried testing
> for that and it appeared to get created.  I created a local object and set
> it equal to the new parameter first, then used the local object in the
> hashtable.add and that failed too.

> - Joe



> > That looks like it should work fine.. are you getting an error?



> > > Is it possible to store objects in a hashtable?  Here's what I am
trying
> > to
> > > do:

> > > dim h1 as HashTable
> > > h1.Add("P1", New Parameter(Name,Value))

> > > In this case Parameter is a class and I am trying to create a new
> instance
> > > of a parameter and store it in the Hashtable.  Thanks for any help.

> > > - Joe



Tue, 13 Jul 2004 06:09:40 GMT  
 Storing Objects in a Hashtable
Boy do I feel stupid.  It was just the "new" that I was missing.  I knew it
should have worked and should have figured it was something as simple as
this.  Thanks everyone!


Quote:
> Yes I get an error: Value null was found where an instance of an object
was
> required.
> Which looks to me like the object doesn't get created, but I tried testing
> for that and it appeared to get created.  I created a local object and set
> it equal to the new parameter first, then used the local object in the
> hashtable.add and that failed too.

> - Joe



> > That looks like it should work fine.. are you getting an error?



> > > Is it possible to store objects in a hashtable?  Here's what I am
trying
> > to
> > > do:

> > > dim h1 as HashTable
> > > h1.Add("P1", New Parameter(Name,Value))

> > > In this case Parameter is a class and I am trying to create a new
> instance
> > > of a parameter and store it in the Hashtable.  Thanks for any help.

> > > - Joe



Tue, 13 Jul 2004 21:49:08 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Iterate through a hashtable, a get an object by Position

2. Problems with variables retaining values with Hashtable of Objects

3. Collection Objects vs. HashTable

4. How to store object to an object array?

5. Storing ATL-object in the Session Object??

6. HashTable DictionaryEntry Update

7. hashtable datagrid

8. MS hashtable ?

9. Combination of hashtable and sortedlist

10. hashtable in session variable

11. Hashtable sorting?

12. loop thru hashtable...

 

 
Powered by phpBB® Forum Software