|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
unbounded array of objects gets error when instantiating elementsI 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 Daniel,
The most simple one for your problem is mos probably the arraylist http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsarraylistclasstopic.asp I hope this helps, Cor You can either use an ArrayList which is unbounded or you can use the
ReDim Preserve method: Dim mParams() as clsParameters ReDim mParams(2) "DanielNoack" <danielno***@hotmail.com> schrieb: 'mParams' doesn't contain any items, thus no item with index 0 exists.> 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' contains four items with indices 0 to 3.> 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 ?? 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/> |
|||||||||||||||||||||||