Solved

Help clarifying a textbook example project

Posted on 2006-07-11
4
219 Views
Last Modified: 2010-04-23
I have been studying creating custom user controls, and am about to start the "Hands-on" programming example.
However, it's as if it's introducing a new feature that wasn't explained in the text.  Could someone clarify what is meant by changing the root namespace in the following:

"Create a Windows user control that ... <blah> <blah> <blah>
This control must make the data ... available to the form...
To share a Person structure between the control and the form, each project must be declared in the same namespace.  By default, each project is created in its own root namespace.  The easiest and best way to change this is to display the Project Properties dialog box and change the root namespace before building the project."

So - why exactly is changing the namespace necessary?  
And what exactly would one change it to?
0
Comment
Question by:sirbounty
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17082353
They're basically saying that your UserControl and your Test Harness project should both be in the same namespace, presumably to simplify the example.

You can change it to whatever you want, just so long as they are the same. So, for example, you might have a line like:

    Namespace MyProject.UserControlSample

At the top of your UserControl class and the form in your test harness project.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17082383
Hmm - maybe my ignorance stems from the usage of 'namespace'.  What is it and how's it used in my project(s)?

Why would they need to share the same namespace and/or what would be the limitation(s) if they did not?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 17082496
Namespaces are simply a way of grouping related objects, they are also used to avoid clashes in object names.

So, if you have two classes both called "Person", if they were in the same namespace then if you used something like:

    Dim p As New Person()

Then the compiler wouldn't know which Person class you meant. However, if you seperate them into seperate namespaces:

    Namespace Customers
        Class Person
        End Class
    End Namespace

    Namespace Contacts
        Class Person
        End Class
    End Namespace

Then you could use:

    Dim p As New Customers.Person()         '// Explicitly state the namespace

Or:

    Imports Customers

    ....

    Dim p As new Person()          '// No need to explictly state namespace because we have "Imported" it


If they are in different namespaces then it just means that you have to Import the namespace in which the UserControl lives, whereas, if they are in the same namespace then you don't need to.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17082526
Thanx! :^)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Disable extension 8 48
Optimize the query 5 43
VB.net SQLCommandBuilder Insert New Records From DataGridView 3 25
Data organization issue 7 16
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question