5 Replies - 8354 Views - Last Post: 05 February 2012 - 01:32 AM Rate Topic: -----

#1 Electrk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-February 12

The name 'Form2' does not exist in the current context

Posted 02 February 2012 - 10:00 PM

Hello, I'm new to C# and I've been using Visual Studio C# 2010. However, it's been quite frustrating for me because it's not working at all and it totally should be. It won't let me open Form2 and it says

The name 'Form2' does not exist in the current context


Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: The name 'Form2' does not exist in the current context

#2 cilaes  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 75
  • Joined: 12-December 11

Re: The name 'Form2' does not exist in the current context

Posted 02 February 2012 - 10:11 PM

You have to create an instance of Form2 in the current context so that it can be identified.

Form2 newForm = new Form2();


That may point you in the right direction. t0q will surely be along to post his ever so helpful FAQ. Search the forums, this is asked a lot!
Was This Post Helpful? 3
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,839
  • Joined: 02-June 10

Re: The name 'Form2' does not exist in the current context

Posted 03 February 2012 - 07:04 AM

This would be the FAQ list Cilaes mentions, that I've compiled to answer a few of these questions that get asked over and over and over and over and over ...

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Form1 talk to Form2



FAQ (Frequently Asked Questions - Updated Jan 2012

Spoiler

Was This Post Helpful? 1
  • +
  • -

#4 Electrk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-February 12

Re: The name 'Form2' does not exist in the current context

Posted 03 February 2012 - 04:28 PM

View Postcilaes, on 02 February 2012 - 10:11 PM, said:

You have to create an instance of Form2 in the current context so that it can be identified.

Form2 newForm = new Form2();


Now it's saying

The type or namespace name 'Form2' could not be found (are you missing a using directive or an assembly reference?)


Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,839
  • Joined: 02-June 10

Re: The name 'Form2' does not exist in the current context

Posted 03 February 2012 - 04:34 PM

Right.. Because the instance of Form2 is called 'newForm'

Its just like when you drag a new button to a form. It isn't called button (that's the class type) Its called "Button1" or you name it "mySendButton".

You have to use the name of the instance you created so it knows which one you are talking about.





I will make a common suggestion though: Quit trying to develop your own application before you lean *how* to code in your chosen language. Trying to write a program from scratch as a learning exercise never works this early in your schooling.

This type of thing is covered very early on in any self-teaching book. Which makes me think you really aren't ready to be designing an application yet.

Some of the tutorials below are for C# not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.

Newbie/Rookie said:

I have a little programming experience but I need to write ...


You need to start there. I can't say "I have little experience in speaking Russian, but I have been assigned to write a mystery novel in Russian. Can you help me?"

We can help you by saying "First learn basic programming and the language of C#. Then take on assignments." Could someone here write this program for you? Sure. Could someone here map out all the processes you need to follow and do the Software Design part of this in the slim hope you could code it from there? Sure. But we don't volunteer to do the job that you're either getting paid for, or getting a grade for. You may want to read this.

For now, just work on the lessons. Do a self-teaching book from cover to cover. Then consider writing a program.

Don't try to create a useful working program to fit a need of yours (or a for-pay contract) as your introduction to coding project. When you are learning to code you don't know enough to code a program, let alone know how to engineer the architecture of a program. It would be like saying "I don't know how to read sheet music, or play an instrument. I think I'll write a 3 act opera as my first learning experience."

I don't say this to be mean. We've seen lots of new coders take this approach and we know it doesn't work. Trying to design your own programs before you understand the basics of the code language you've chosen just leads to problems, frustrations, and 'swiss-cheese' education (lots of holes).


Resources, references and suggestions for new programmers. - Updated Jan 2012
Spoiler

Was This Post Helpful? 1
  • +
  • -

#6 cilaes  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 75
  • Joined: 12-December 11

Re: The name 'Form2' does not exist in the current context

Posted 05 February 2012 - 01:32 AM

Take in the content that toq is giving you, I realized extremely quickly once I bough a book what they actually meant by what they're posting. If you're new to OOP then it's awesomely different yet you'll realize a fix to your problem very soon.

Good Luck in your venture, but it takes nothing to learn the basics, yet the pay off is EXTREMELY useful. :bananaman:
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1