Error: Does not exist in the current context

C

C#novice

Like my name says I am a total novice at C#. I am trying to following
examples in a book that I have but unfortunately they do not provide you with
code for the whole project. Up till now I could figure out what is causing
my problems but now I am stuck. I added in the books code into a Windows
Application:
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsApplication1
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
}

private void btnClickMe_Click(object sender, System.EventArgs e)
{
string msg = " ";
if (txtBeatle.Text == "John")
goto john;
if (txtBeatle.text == "Ringo")
goto ringo;
goto done;
john:
msg = "I like John best, too!";
goto done;
ringo:
msg = "Are you a drummer?";
goto done;
done:
if (msg != " ")
MessageBox.Show(msg, "Beatle choice",
MessageBoxButtons.OK);
}

}
}
When I try to compile the code it displays an error ‘txtBeatle’ does not
exist in the current context. txtBeatle does not look like a variable
because it has .Text behind it. Could somebody be so kind as to tell what I
need to do to fix the problem.
 
M

Martin Honnen

C#novice said:
private void btnClickMe_Click(object sender, System.EventArgs e)
{
string msg = " ";
if (txtBeatle.Text == "John")

When I try to compile the code it displays an error ‘txtBeatle’ does not
exist in the current context. txtBeatle does not look like a variable
because it has .Text behind it. Could somebody be so kind as to tell what I
need to do to fix the problem.

Is 'txtBeatle' a control in your main form? Then it should suffice to
move the btnClickMe_Click method into the code file of your form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top