hi, so im a newbie at coding, im trying to learn some c# (i think i have it down somewhat) but i cant figure out why it's giving me this error..if someone could give me a hand that would be great :)

The name 'Send' does not exist in the current context
lines: 30, 31, 40

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Equals(""))
                return;
            Thread thread = new Thread(SendText);
            thread.Start();
        }
        private void SendText()
        {
            String text = textBox2.Text;
            Send = true;
            while (Send)
            {
                SendKeys.SendWait(text);
                SendKeys.SendWait("{ENTER}");
                System.Threading.Thread.Sleep(1000);
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Send = false;
        }
    }
}

Recommended Answers

All 2 Replies

It looks like you tried to initialize Send but you did not declare it. Try this.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        bool Send;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Equals(""))
                return;
            Thread thread = new Thread(SendText);
            thread.Start();
        }
        private void SendText()
        {
            String text = textBox2.Text;
            Send = true;
            while (Send)
            {
                SendKeys.SendWait(text);
                SendKeys.SendWait("{ENTER}");
                System.Threading.Thread.Sleep(1000);
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Send = false;
        }
    }
}

Declare your Send variable just after your class declaration.

I'm learning too so if I'm off on this someone let me know.

You will have some new errors when you fix this problem.
Your error is a result of calling a variable you havent declared (as Cory_Brown correctly pointed out) but you are also making inter-thread calls which will throw errors. You can't access variables/controls in your main form from a new thread unless you use a delegate. You could use a ParameterizedThreadStart Delegate, this allows you to pass a paramter to the thread when you start it, so you could send it textBox2.text.
Also, you set the value for text at the start of the threa method but never change it, so each time the thread wakes it will resend the same text...was that intentional?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.