From: spam@qeidrafting.com   
      
   Thanks Alfie & Dee for your responses.   
   I will go with a temporary variable and a collection. I thought the   
   collection.add statement was only adding a reference back to the variable   
   and therefor requiring me to keep the variable. I see that is not the case   
   so the variable can be temporary.   
      
   Cheers guys :)   
      
      
   "Dee Earley" wrote in message   
   news:4a3209dd$0$348$7b0f0fd3@reader.news.newnet.co.uk...   
   > On 12/06/2009 05:46, Moiv wrote:   
   >> In my VB2008 project if I have created a class called Aircraft.   
   >> For testing I have hard coded 2 aircraft into my project (as seen below).   
   >> Ultimately I will want an unlimited number of aircraft to be read from a   
   >> database or text file.   
   >> How does one initialise an unknown number of Aircraft objects? As it   
   >> appears   
   >> each object instance needs to be assigned to a variable.   
   >> One idea I had was to write a function (or perhaps "method" in this OOP   
   >> world) that redims an array to a larger size each time it is called and   
   >> then   
   >> initialises a new aircraft object and assigns it to the new position at   
   >> the   
   >> end of the array.   
   >> Surely there is a more correct way of doing this, I have read through the   
   >> object section of the help many times and cannot find an example of what   
   >> to   
   >> do here. All the examples tend to deal with only 2 or 3 instances of an   
   >> object.   
   >> Any tips would be appreciated.   
   >   
   > A collection or List is the way to go.   
   >   
   >> Dim aircraftColl As New System.Collections.Generic.Dictionary(Of String,   
   >> Aircraft)   
   >>   
   >> Dim testobj As New Aircraft("Cessna 172RG")   
   >>   
   >> testobj.BaseWeight = 734   
   >> testobj.MTOW = 1202   
   >> testobj.FuelBurn = 40   
   >> testobj.TotalFuel = 250   
   >> testobj.UsableFuel = 235   
   >> testobj.TAS = 125   
   >>   
   >> Dim testobj2 As New Aircraft("Cessna 172M")   
   >>   
   >> testobj2.BaseWeight = 664   
   >> testobj2.MTOW = 1043   
   >> testobj2.FuelBurn = 35   
   >> testobj2.TotalFuel = 190   
   >> testobj2.UsableFuel = 146   
   >> testobj2.TAS = 105   
   >>   
   >> aircraftColl.Add(testobj.Name, testobj)   
   >> aircraftColl.Add(testobj2.Name, testobj2)   
   >   
   > Use the same object variable for each and add it to the collection before   
   > creating the next one.   
   > The local variable is only needed temporarily until you put it in the   
   > collection.   
   >   
   > Oh, and this newsgroup is for classic VB, not VB.Net.   
   >   
   > --   
   > Dee Earley (dee.earley@icode.co.uk)   
   > i-Catcher Development Team   
   >   
   > iCode Systems   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|