title: How a variable can be recognized from button to method?
body: <p>I'm trying to count the number of words and characters in a specific text. Now this all works fine but I want to tidy up code so that I don't have to include the the you see under <code>newSummaryMethod()</code> into every button, hence why I have placed it in it's own method. But when I do this, it doesn't count the words and characters. Now I know the reason is that <code>string copyText = "";</code> in the method, that's because if I don't declare that string variable, then I will get syntax errors in my button that <code>copyText</code> is not declared.</p>
  
  <p>My question is really about how can I get the <code>newSummaryMethod</code> to know that it needs to communication with the <code>copyText</code> in first the vowels button? I have another button where <code>copyText</code> may behave a bit differently so I think I need the button to communicate with the method.</p>
  
  <pre><code> private void newSummaryMethod() {
       string copyText = "";
  
       /*Count number of lines in processed text,
  extra line is always counted so -1 brings it to correct number*/
       int numLines = copyText.Split('\n').Length - 1;
  
       //seperate certain characters in order to find words
       char[] seperator = (" " + nl).ToCharArray();
  
       //number of words, characters and include extra line breaks variable
       int numberOfWords = copyText.Split(seperator, StringSplitOptions.RemoveEmptyEntries).Length;
       int numberOfChar = copyText.Length - numLines;
  
       //Unprocessed Summary
       newSummary = nl + "Word Count: " + numberOfWords + nl + "Characters Count: " + numberOfChar;
   }
  
   private void btnVowels_Click(object sender, EventArgs e) {
       //Strip vowels
       string vowels = "AaEeIiOoUu";
       string copyText = richTextBox1.Text;
       copyText = new string(copyText.Where(c =&gt; !vowels.Contains(c)).ToArray());
  
       newSummaryMethod();
  
       //Write into richTextBox2
       wholeText = richTextBox1.Text + oldSummary + copyText + newSummary;
       Write(Second_File, wholeText);
       richTextBox2.Text = wholeText;
   }
  
   private void btnAlpha_Click(object sender, EventArgs e) {
  
       //Remove non alpha characters
       string nonAlpha = @"[^A-Za-z ]+";
       string addSpace = "";
       string copyText = richTextBox1.Text;
       copyText = Regex.Replace(copyText, nonAlpha, addSpace);
  
       newSummaryMethod();
  
       //Write into richTextBox2
       wholeText = richTextBox1.Text + oldSummary + copyText + nl + newSummary;
       Write(Second_File, wholeText);
       richTextBox2.Text = wholeText;
  
   }
  </code></pre>