https://img.ourl.ca/rfg/Form2Problem.png

Hello everybody, I've always used this code to show another form:


Code:
FormName extraForm = new FormName();
extraForm.Show();


I'm getting an error, any ideas?

Edit by Merth: Image was too big.
Make sure the Form2 class is in the same Namespace as the Form1 class.
merthsoft wrote:
Make sure the Form2 class is in the same Namespace as the Form1 class.
Who's the man? Shaun's the man. That sounds like a perfectly logical explanation of the error to me.
merthsoft wrote:
Make sure the Form2 class is in the same Namespace as the Form1 class.


Yeah, I eventually found that was the problem.

However, the namespace of Form1 is MP3_Player and the namespace of the Form2 is mePlaysMedia

Form1:

Code:
namespace MP3_Player


Form2:

Code:
namespace mePlaysMedia


I tried putting both and I get errors, how should I do it?
They should have the same namespace, like I said. So either namespace MP3_Player or namespace mePlaysMedia. If you can't (or don't want to) have them in the same namespace, you'll have to us a using directive at the top and do using MP3_Player or using mePlaysMedia. If you right-click on Form2 where you're declaring it, it should have a "Resolve" menu item, and you can click to make it either do "using mePlaysMedia" at the top, or it can make it do "mePlaysMedia.Form2".
Just to clarify why "putting both" yielded errors, an object can only be in one namespace. Putting it in multiple namespaces would be like giving your house two different addresses.
Thanks shaun, I decided to create a new Project and copy it all, though.
merthsoft wrote:
Make sure the Form2 class is in the same Namespace as the Form1 class.


awww, finally an easy problem I could answer, and merth beat me to it. /kill school Razz

on topic: this sounds perfectly fine to me Smile
ScoutDavid wrote:
Thanks shaun, I decided to create a new Project and copy it all, though.
That's one way to do it, I guess.
merthsoft wrote:
They should have the same namespace, like I said.


No, they shouldn't. That is the completely wrong answer. Namespaces exist for a *very* good reason, use them. All he needs is a using statement or to fully qualify it, eg: new MP3_Player.Form();
Kllrnohj wrote:
merthsoft wrote:
They should have the same namespace, like I said.


No, they shouldn't. That is the completely wrong answer. Namespaces exist for a *very* good reason, use them.
Oh, huh, I thought they were just completely arbitrary, useless constructs made to make life more difficult.
merthsoft wrote:
Kllrnohj wrote:
merthsoft wrote:
They should have the same namespace, like I said.


No, they shouldn't. That is the completely wrong answer. Namespaces exist for a *very* good reason, use them.
Oh, huh, I thought they were just completely arbitrary, useless constructs made to make life more difficult.
Good thing Kllrnohj was able to teach you a lesson, then! It's unfortunate that you didn't look at Scout's usage and see that in this case, he indeed was using his objects in such a way that they should be in the same namespace.
merthsoft wrote:
Oh, huh, I thought they were just completely arbitrary, useless constructs made to make life more difficult.


That sounds a lot like sarcasm, so let me give you a tip. Namespaces are *AWESOME*. They are one of the few things that are so good that languages without them try and emulate them. Most C projects try and emulate namespaces. GTK, for example, has functions like gtk_window_show and g_signal_connect - where gtk and g would be the respective namespaces in a language that actually has them.

Namespaces are why you don't have the compiler constantly complaining that your function or variable is colliding with the function name in some random library.

I have no idea how namespaces could possibly be getting in your way. Any half-decent IDE will automatically import namespaces as needed anyway. So if you find namespaces frustrating, you should probably just give up programming.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement