Gerard2202
Gerard2202

Reputation: 151

c# send skype message to users unless textbox is empty

My Skype application has a fetcher that can send a message to people on the users contact list. The contacts that the message is sent to are entered into text boxes.

 private void button1_Click(object sender, EventArgs e)
        {
            var oskype = new SKYPE4COMLib.Skype();
          oskype.SendMessage(textBox1.Text, textBox2.Text); //com error happens in this zone
            oskype.SendMessage(textBox11.Text, textBox2.Text);
            oskype.SendMessage(textBox3.Text, textBox2.Text);
            oskype.SendMessage(textBox4.Text, textBox2.Text);
            oskype.SendMessage(textBox5.Text, textBox2.Text);
            oskype.SendMessage(textBox6.Text, textBox2.Text);
            oskype.SendMessage(textBox7.Text, textBox2.Text);
            oskype.SendMessage(textBox8.Text, textBox2.Text);
            oskype.SendMessage(textBox9.Text, textBox2.Text);
            oskype.SendMessage(textBox10.Text, textBox2.Text);
}

I also have a RichTextBox that acts as a log, and when the message is sent, it writes to the log saying that the message was sent. But when the text box is empty, it writes to the log "System.Windows.Forms.TextBox, Text: ", but instead I want it to write something like "Invalid Contact", or not write anything.

richTextBox1.Text += Environment.NewLine;
            richTextBox1.Text += "Sending message to :" + Environment.NewLine;
            richTextBox1.Text += textBox1.Text + Environment.NewLine;
            richTextBox1.Text += textBox11.Text + textBox3.Text + textBox4.Text + textBox5.Text + textBox6.Text + textBox7.Text + textBox8.Text + textBox9.Text + textBox10.Text;

And if the text entered into the text box in not on the persons contact list, it produces an error just basically saying that it cannot find that user but is there a way of making it ignore the empty text box and not try to send it to Skype? If you need more detail, please just ask.

Upvotes: 0

Views: 1063

Answers (2)

Cullub
Cullub

Reputation: 3258

Try this

Private bool checkBoxEmpty (textBox tb) {
    if (tb.text != ""){
        return false;
    }
    else {
        return true;
    }
}

And just call this for each text box.

Hope it helps!

Upvotes: 1

Kendall Frey
Kendall Frey

Reputation: 44374

textBox11.Text + textBox3 + textBox4 + ...

You forgot to do .Text on most of them.

Upvotes: 1

Related Questions