Wrox Programmer Forums
|
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 14th, 2004, 04:04 AM
Authorized User
 
Join Date: Jul 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parenthesis - question

Hi all,

In the book there are quite a lot of code examples where parenthesis are added at the end of an object, however, when typing these into Visual Studio it lops them back off again, an example of this is on page 398.

' create a new user
Dim objUser As New User()

when this is entered into Visual Studio I get

' create a new user
Dim objUser As New User

I was just wondering if anyone could explain why this happens, I'm assuming they are not needed (or else VS wouldn't remove them) - but I would like to understand why they are removed, and also - I swear that sometimes they aren't (but I might be wrong on this one), I just seem to remember typing code where for example

User() remained as that.

Any information would be appreciated.


Regards

Rob
__________________
Regards

Rob
 
Old August 15th, 2004, 04:19 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Rob,

It seems, unbeknownst to me, that parenthesis are not always required when calling a constructor for a class, even if the class provides one or more overloaded methods.

However, parentheses are required when calling procedures and functions, even if they don’t accept parameters. That’s the best that I can tell you at this point.

Thearon
 
Old August 15th, 2004, 06:41 AM
Authorized User
 
Join Date: Jul 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Thearon,

Thanks for the reply, hmm..tis an odd one...its not really a big issue, I was just wondering why sometimes they are there, and sometimes they get removed (and how does it know!).. :)




Regards

Rob
 
Old August 16th, 2004, 08:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

When declaring an object like that (using VB.NET syntax), the parameters are ripped off because VB.NET doesn't care about those being there (syntax-wise). C# uses them because of its syntax:

User objUser = New User();

For C#, they are required like this, but because you are declaring a new type in VB.NET, it doesn't like them (except when declaring parameters for the new constructor). I think it's because it is regarding it as a type instead of a new class definition, but I don't really know if that's it.

It knows because it is a variable declaration (Dim statement). Those Microsoft folks are pretty smart, whether you believe that or not. :D

Brian
 
Old August 17th, 2004, 08:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Now that I think about it, the parameter removal in VB.NET is more of a VS.NET standard than anything else. Each language has a required syntax, and if you used a different editor, I don't think it would throw an error if you had parenthesis for:

Dim o As New User()

However, VS.NET standard doesn't like (). I think that's what it is. For the C# example in the previous post, the () are needed.

Brian

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
yes or no question grstad Classic ASP Databases 0 April 14th, 2006 04:37 AM
contains() question... CyanBlue XSLT 3 April 6th, 2006 03:37 AM
Question Ashwini Classic ASP Databases 3 January 10th, 2006 07:20 AM
a question gorji C++ Programming 2 August 11th, 2003 07:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.