I need a little help with the below code. I am basically reading text from a .txt file and need to be able to convert the text into an array(fam6) that i can then search for a value that is typed into a text box. If said text box search is not found i want to reply with a default message. My if then statement is really off and i would greatly apprecaite someone helping me correct my code.

private void button1_Click(object sender, EventArgs e)
        {
            string[] fam6 = System.IO.File.ReadAllLines(@"C:\Users\Beginerman\Documents\Visual Studio 2008\Projects\ArraySearch\ArraySearch\fam6.txt");

            string value1 = Array.Find(fam6, element => element.StartsWith(textBox1.Text, StringComparison.Ordinal));

            if (fam6.Contains(textBox1))
            textBox2.Text = "Your search phrase was not found." + "\r\n";
                textBox2.AppendText("We compared your search to 6 items.");
            else (textBox1.Text.Length == (0))
             textBox2.Text = "You did not enter data in the search box please enter a search request.";
            else
            {textBox2.Text = value1 + "\r\n" + "\r\n";
            textBox2.AppendText("The system found your search phrase and has displayed it above." + "\r\n");
            textBox2.AppendText("We compared your search to 6 items.");}
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

try this in place of line 7-16

if (fam6.Contains(textBox1))
{
        textBox2.Text = value1 + "\r\n" + "\r\n";
        textBox2.AppendText("The system found your search phrase and has displayed it above." + "\r\n");
        textBox2.AppendText("We compared your search to 6 items.");
}
else
{
    if (textBox1.Text.Length == (0))
    {
        textBox2.Text = "You did not enter data in the search box please enter a search request.";
    }
    else
    {
        textBox2.Text = "Your search phrase was not found." + "\r\n";
        textBox2.AppendText("We compared your search to 6 items.");

    }
}

Your awesome and i apologize for my late acknowledgement. The code worked perfect and definatley helps in my advancement of C# programming. Thanks again tinstaafl.

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.