Go Back  PPRuNe Forums > Misc. Forums > Computer/Internet Issues & Troubleshooting
Reload this Page >

Why does VB .net have a constructor?

Wikiposts
Search
Computer/Internet Issues & Troubleshooting Anyone with questions about the terribly complex world of computers or the internet should try here. NOT FOR REPORTING ISSUES WITH PPRuNe FORUMS! Please use the subforum "PPRuNe Problems or Queries."

Why does VB .net have a constructor?

Thread Tools
 
Search this Thread
 
Old 12th Apr 2006, 00:02
  #1 (permalink)  

I'matightbastard
Thread Starter
 
Join Date: Jul 2001
Location: Texas
Posts: 1,747
Likes: 0
Received 0 Likes on 0 Posts
Why does VB .net have a constructor?

I'm really having trouble coming to terms with this... Why do I have to type:

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

why isn't it just

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

Why does it need a New in there?

I mean Dim is a declaration, why doesn't that declare a new thingie for me?

Onan the Clumsy is offline  
Old 12th Apr 2006, 09:34
  #2 (permalink)  
 
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  
Old 12th Apr 2006, 16:29
  #3 (permalink)  
Fixed+Rotary (aircraft, not washing lines)
 
Join Date: Jan 2005
Location: Peak District, Yorkshire, UK
Age: 56
Posts: 357
Likes: 0
Received 0 Likes on 0 Posts
drauk. That's a bloody good way of explaining this, I shall keep it up my sleeve for future reuse...
MyData is offline  
Old 13th Apr 2006, 14:00
  #4 (permalink)  

I'matightbastard
Thread Starter
 
Join Date: Jul 2001
Location: Texas
Posts: 1,747
Likes: 0
Received 0 Likes on 0 Posts
Thanks. I'm mulling that over. I think I might have to forget a lot of mainframe development experience before I become fully comfortable in this new environment. I'm used to a declaration being all you need:

01 WS-VARIABLE PIC X(8).

Onan the Clumsy is offline  
Old 14th Apr 2006, 13:25
  #5 (permalink)  
Fixed+Rotary (aircraft, not washing lines)
 
Join Date: Jan 2005
Location: Peak District, Yorkshire, UK
Age: 56
Posts: 357
Likes: 0
Received 0 Likes on 0 Posts
Onan

I managed to avoid mainframes in my previous life as a code monkey (but did dabble on VAXs for a while).

My upbringing was on C and then C++. Although I program in VB.NET these days for ease of use to knock up prototypes I do miss the rigour and structure that C/C++ enforced in that if you did something implicitly then it might compile, it might execute, but later down the line it would come back to bite you.

VB tends to be a happy medium of easy to understand syntax, but sometimes it allows the programmer to do things the easy way and makes assumptions on your behalf.
MyData is offline  

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Contact Us - Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service

Copyright © 2024 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.