By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,288 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

unbounded array of objects gets error when instantiating elements

P: n/a
Hi,
I have a problem that I am unable to get an array of objects to
instantiate properly when it is declared with no upper bound. My code
is as follows
dim mParams() as clsParameters
mParams(0) = new clsParameters

produces an error saying mParams is set to nothing however if I change
the declaration to have an upper bound it works like
dim mParams(3) as clsParameters
mParams(0) = new clsParameters
this works but I need the array to be unbounded, does anyone know what
I am doing wrong or if this is possible to have an unbounded array of
objects in VB.NET ??

Thanks for any help.
Daniel
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You can either use an ArrayList which is unbounded or you can use the
ReDim Preserve method:

Dim mParams() as clsParameters
ReDim mParams(2)

Nov 21 '05 #2

P: n/a
Daniel,

The most simple one for your problem is mos probably the arraylist

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor
Nov 21 '05 #3

P: n/a
"DanielNoack" <da*********@hotmail.com> schrieb:
I have a problem that I am unable to get an array of objects to
instantiate properly when it is declared with no upper bound. My code
is as follows
dim mParams() as clsParameters
mParams(0) = new clsParameters

produces an error saying mParams is set to nothing however if I change
the declaration to have an upper bound it works like
'mParams' doesn't contain any items, thus no item with index 0 exists.
dim mParams(3) as clsParameters
mParams(0) = new clsParameters
'mParams' contains four items with indices 0 to 3.
this works but I need the array to be unbounded, does anyone know what
I am doing wrong or if this is possible to have an unbounded array of
objects in VB.NET ??


\\\
Dim Parameters() As Parameter = {New Parameter(), New Parameter()}
///

You can change an array's size later using 'ReDim Preserve'. Notice that
'ReDim Preserve' will create a new array of the desired size and copy the
contents of the old array to the new array, which is a costly process,
especially for larger arrays.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.