home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 10,777 of 10,840   
   Dee Earley to Moiv   
   Re: Initialising an unknown number of ob   
   12 Jun 09 09:01:22   
   
   From: dee.earley@icode.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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca