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,776 of 10,840   
   Moiv to All   
   Initialising an unknown number of object   
   12 Jun 09 04:46:58   
   
   From: spam@qeidrafting.com   
      
   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.   
      
   Thanks in advance   
      
      
      
   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)   
      
   Dim aPair As KeyValuePair(Of String, Aircraft)   
      
   For Each aPair In aircraftColl   
   ComboBox1.Items.Add(aPair.Value.Name)   
   Next aPair   
      
   --- 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