Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 14th, 2004, 04:04 AM
Authorized User
 
Join Date: Jul 2004
Location: Bristol, , United Kingdom.
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
  #2 (permalink)  
Old August 15th, 2004, 04:19 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
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
  #3 (permalink)  
Old August 15th, 2004, 06:41 AM
Authorized User
 
Join Date: Jul 2004
Location: Bristol, , United Kingdom.
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
  #4 (permalink)  
Old August 16th, 2004, 08:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
  #5 (permalink)  
Old August 17th, 2004, 08:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:42 PM.


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