Solved

Help clarifying a textbook example project

Posted on 2006-07-11
4
218 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

806 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