Solved

Help clarifying a textbook example project

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

947 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now