Home All Groups Group Topic Archive Search About

New obj() vs. New obj

Author
5 Jun 2006 1:09 AM
Erik
Hi all,

I am interested in discerning the difference from my textbook and the
actual behavior of the MS Dev IDE 2003.

My textbook specifies:

objOleDbCommand = New OleDbCommand()

I type that in the VB Editor. However when I end the line and start
typing the next code line, the editor automatically removes the closing
parentheses () from end of the line so that it leaves this:

objOleDbCommand = New OleDbCommand

Any idea why this is? I wonder if this is something new in the MS Dev
Environment for version 2003.

Any time I put an arg in the the parens, then the IDE does not delete
them.

Thanks,
Erik

Author
5 Jun 2006 2:09 AM
rmacias
In VB.NET when instantiating a new object via its parameterless constructor
does not need the empty parethesis "()".  However, using a constructor with
parameter does require them.

It's an IDE feature to remove them.  I don't know the reason for that, but
they mean the same thing. 

Show quoteHide quote
"Erik" wrote:

> Hi all,
>
> I am interested in discerning the difference from my textbook and the
> actual behavior of the MS Dev IDE 2003.
>
> My textbook specifies:
>
> objOleDbCommand = New OleDbCommand()
>
> I type that in the VB Editor. However when I end the line and start
> typing the next code line, the editor automatically removes the closing
> parentheses () from end of the line so that it leaves this:
>
> objOleDbCommand = New OleDbCommand
>
> Any idea why this is? I wonder if this is something new in the MS Dev
> Environment for version 2003.
>
> Any time I put an arg in the the parens, then the IDE does not delete
> them.
>
> Thanks,
> Erik
>
>
Author
5 Jun 2006 9:38 AM
Herfried K. Wagner [MVP]
"rmacias" <rmacias@newsgroup.nospam> schrieb:
> In VB.NET when instantiating a new object via its parameterless
> constructor
> does not need the empty parethesis "()".  However, using a constructor
> with
> parameter does require them.
>
> It's an IDE feature to remove them.  I don't know the reason for that, but
> they mean the same thing.

The intention for automatically removing the '()' on constructor calls was
to visually disambiguish constructor calls from array declarations:

\\\
Dim a As New Object() {}
Dim b As New Object
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
5 Jun 2006 10:08 PM
rmacias
Ahhhhh......that make total sense now.

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "rmacias" <rmacias@newsgroup.nospam> schrieb:
> > In VB.NET when instantiating a new object via its parameterless
> > constructor
> > does not need the empty parethesis "()".  However, using a constructor
> > with
> > parameter does require them.
> >
> > It's an IDE feature to remove them.  I don't know the reason for that, but
> > they mean the same thing.
>
> The intention for automatically removing the '()' on constructor calls was
> to visually disambiguish constructor calls from array declarations:
>
> \\\
> Dim a As New Object() {}
> Dim b As New Object
> ///
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
5 Jun 2006 2:04 PM
Jim Wooley
Show quote Hide quote
> Hi all,
>
> I am interested in discerning the difference from my textbook and the
> actual behavior of the MS Dev IDE 2003.
>
> My textbook specifies:
>
> objOleDbCommand = New OleDbCommand()
>
> I type that in the VB Editor. However when I end the line and start
> typing the next code line, the editor automatically removes the
> closing parentheses () from end of the line so that it leaves this:
>
> objOleDbCommand = New OleDbCommand
>
> Any idea why this is? I wonder if this is something new in the MS Dev
> Environment for version 2003.
>
> Any time I put an arg in the the parens, then the IDE does not delete
> them.

I don't have a copy with me to test, but I believe either the 2002 version
or one of it's beta versions required the (). Most likely the textbook was
written with one of these early versions and not updated when the more recent
versions were released. The reason for removing the () from the constructor
is to dis-ambiguate the type from the array version of the type.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Author
8 Jun 2006 6:30 AM
Erik
Thanks to all of you for the very sensible explanations!

Erik.

Jim Wooley wrote:
Show quoteHide quote
> > Hi all,
> >
> > I am interested in discerning the difference from my textbook and the
> > actual behavior of the MS Dev IDE 2003.
> >
> > My textbook specifies:
> >
> > objOleDbCommand = New OleDbCommand()
> >
> > I type that in the VB Editor. However when I end the line and start
> > typing the next code line, the editor automatically removes the
> > closing parentheses () from end of the line so that it leaves this:
> >
> > objOleDbCommand = New OleDbCommand
> >
> > Any idea why this is? I wonder if this is something new in the MS Dev
> > Environment for version 2003.
> >
> > Any time I put an arg in the the parens, then the IDE does not delete
> > them.
>
> I don't have a copy with me to test, but I believe either the 2002 version
> or one of it's beta versions required the (). Most likely the textbook was
> written with one of these early versions and not updated when the more recent
> versions were released. The reason for removing the () from the constructor
> is to dis-ambiguate the type from the array version of the type.
>
> Jim Wooley
> http://devauthority.com/blogs/jwooley/default.aspx