PPRuNe Forums - View Single Post - Why does VB .net have a constructor?
View Single Post
Old 12th Apr 2006, 09:34
  #2 (permalink)  
drauk
 
Join Date: Sep 2002
Location: London, UK
Posts: 778
Likes: 0
Received 0 Likes on 0 Posts
The Dim is a declaration of the fact that a variable ('custDS') is a reference to a dataset object. It could be that one dataset that you're just about to create, it could be another dataset that you create later on, or it could be one you've already created elsewhere. Building a load of wooden pigeon holes doesn't create the letters that you put in them, rather just gives you space to put the letters when they arrive.

"New" creates an INSTANCE of an object. Hence you need the declaration and the constructor if what you want is a new instance of an object and a reference to it.

As to:

Dim custDS As DataSet
Set custDS = ("CustomerOrders")

The first line is fine; you're making a variable which will be a reference to a dataset. But in the second line, how does the interpreter know exactly what you want to create? You might suggest that it could infer it from the type of custDS (which it knows is "DataSet"), but it might be another type of object which descends from a DataSet; how can it know unless you tell it? That's polymorphism at work and is a powerful feature of object oriented languages.
drauk is offline