Also "New Collection" as an argument
I was surprised to find such constructs allowed in VB6 too, you expect such
things in Java or Smalltalk and other OO languages. Which may be why we see
it allowed in VB.
Also.... you may have noticed .... if you declare a sub that takes a
Collection as arg (or some other type) then you can pass "New Collection",
in place of a symbol initialized to a Collection. Also, you can also
Nothing as an argument to that sub and it will pass the type checking, which
you'd expect in other OO languages. But it did feel like a bit of a walk
on the wild side for VB, when I noticed it working!
Maybe this was preparation for VB7, when more and more "standard" OO ideas
are going to be allowed in VB, like constructors with arguments. Seems VBs
first priority in the past is to be more plodding and foolproof, for people
new to programming. Now, it's supposed to feel ALSO like a "real OO"
language to people trying it from other programming backgrounds.
From trad VB point of view, allowing this isn't necessary, can't save more
than a line or 2 of code.
But I still like it. In your construct, you might have been constructing a
business object collection that is part of your project, outside it's normal
scope, just to get a report from it. E.g. total of a certain value for all
items. I don't think it adds any clarity to declare and instantiate that
collection separately, it feels more elegant to write code like yours.
Works either way ... but it is a bit of a relief that VB7 will follow more
OO standards, even including less formal behavior like this. .
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center