Click here to Skip to main content
15,917,005 members

Comments by Member 10274631 (Top 5 by date)

Member 10274631 20-Sep-13 0:35am View    
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
double a, b, r; // to represent textboxes
string result = textBox4.Text.ToString(); // to represent the result
string Operation = textBox2.Text.ToString(); // to represent the operation

{
switch (Operation)
{
case "+":
a = double.Parse(textBox1.Text); // input string incorrect format
b = double.Parse(textBox3.Text); // if I leave blank
r = a + b;
textBox4.Text = r.ToString();
break;

case "-":
a = double.Parse(textBox1.Text);
b = double.Parse(textBox3.Text);
r = a - b;
textBox4.Text = r.ToString();
break;

case "*":
a = double.Parse(textBox1.Text);
b = double.Parse(textBox3.Text);
r = a * b;
textBox4.Text = r.ToString();
break;

case "/":
a = double.Parse(textBox1.Text);
b = double.Parse(textBox3.Text);
r = a / b;
textBox4.Text = r.ToString();
break;

default: // if the user input a value not in the operation.
textBox4.Text = "Cannot compute";
break;
}
if (String.IsNullOrEmpty(textBox1.Text)) // if user input nothing in textBox2
{
label6.Text = "Please enter the first number"; // label7 should appear this text.
}
if (String.IsNullOrEmpty(textBox2.Text)) // if user input nothing in textBox2
{
label7.Text = "Please enter an operator"; // label7 should appear this text.
}
if (String.IsNullOrEmpty(textBox3.Text)) // if user input nothing in textBox2
{
label8.Text = "Please enter the secong number"; // label7 should appear this text.
}
{
}
}
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text.ToString();
}

private void textBox2_TextChanged(object sender, EventArgs e)
{


}

private void textBox3_TextChanged(object sender, EventArgs e)
{
textBox3.Text = textBox3.Text.ToString();
}

private void textBox4_TextChanged(object sender, EventArgs e)
{
textBox4.Text = textBox4.Text.ToString();
}

private void label6_Click(object sender, EventArgs e)
{

}

}
}



a = double.Parse(textBox1.Text); // if I leave blank textbox1 incorrect input
b = double.Parse(textBox3.Text); // same in textbox3 leave blank incorrect input.

What I did wrong here?
Member 10274631 15-Sep-13 11:50am View    
I follow your instruction
Here is my revise code

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string strReplace = textBox2.Text;
}

private void button1_Click(object sender, EventArgs e)
{
string Replace = strReplace;

if (textBox1.Text.Contains(textBox2.Text))
{
textBox3.Text = "" + textBox1.Text.Replace(strReplace, string.Empty).ToUpper();
}
else
{
textBox3.Text = "I cannot subtract the word "";
}

textBox3.Text = textBox1.Text.Replace(textBox2.Text, "").ToUpper();
textBox4.Text = textBox1.Text.Replace(textBox2.Text, "").ToLower();
textBox5.Text = textBox1.Text.Length.ToString();

}

private void textBox2_TextChanged(object sender, EventArgs e)
{
It subtract the word in textbox2 that match in textbox1 but it will not show if the word was not match, "I cannot subtract the word "(user typed word in textbox2)" // it suppose to catch the word that user type in the parenthesis. It means else is not working. I am not suppose to use Unicode.

A little bit more of your help and I will be done on this one.
Thank you.
Member 10274631 15-Sep-13 1:17am View    
This is a test (textbox1)
is a (textbox2)
THIS TEST (textbox3)
this test (textbox4)


This is a test (textbox1)
apple (textbox2)
I cannot subtract the word <apple> (textbox3)//this is the error that need to show if the word was not found on textbox1.
this test (textbox4)

Again, thank you for your help.
Member 10274631 15-Sep-13 1:12am View    
if the word/s can be found on textbox1 it must be sutracted and will show the remaining words in textbox3 and 4.
Member 10274631 15-Sep-13 1:03am View    
Bill I will not post my problem here if I know how to start the if statement on this case. Yes I know how to put the text in upper and lower case.