I am creating a spam email checker. One method scans the email, another adds a known flag to an array of words and phrases to check against; both methods are part of Teste
Variables declared inside of a method (as yours are) have method scope, so they can't be seen by other methods.
Instead, declare the variable in the class scope so that both the class's methods can see it.
public partial class Spam_Scanner : Form
{
private Tester scan;
private void testButton_Click(object sender, EventArgs e)
{
scan = new Tester();
...
}
private void addButton_Click(object sender, EventArgs e)
{
scan.addSpam(Convert.ToString(addFlagBox.Text));
...
}
}
Depending on the order of button clicks, you may want to initialize the variable in the declaration rather than in the testButton_Click method, but thats up to you. The important thing to remember is that scopes can see their own members, and all scopes they are nested in. Thus, methods can see class-scope variables, but not each other's.
Move the Tester
variable to the class field, like this:
public partial class Spam_Scanner : Form
{
Tester scan;
public Spam_Scanner()
{
InitializeComponent();
scan = new Tester();
}
private void testButton_Click(object sender, EventArgs e)
{
scan.tester(Convert.ToString(emailBox.Text));
this.SpamRatingBox.Text = string.Format("{0:N1}%", Tester.countSpam / Tester.wordCount * 100);
this.WordsBox.Text = Tester.posSpam;
this.OutputPanal.Visible = true;
this.pictureBox1.Visible = false;
}
private void addButton_Click(object sender, EventArgs e)
{
scan.addSpam(Convert.ToString(addFlagBox.Text));
this.addFlagBox.Text = "";
}
}