Act1 (Substring)
Act1 (Substring)
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int length2 ;
int input1,input2;
int total;
String operation;
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
switch (Trigger) {
case "+" :
length2 = length1 + 1;
String subAdd = txtbox1.Substring(0, length2 - 1);
input1 = Convert.ToInt32(subAdd);
operation = "+";
break;
case "-":
length2 = length1 + 1;
String subMinus = txtbox1.Substring(0, length2 - 1);
input1 = Convert.ToInt32(subMinus);
operation = "-";
break;
case "/":
length2 = length1 + 1;
String subDiv = txtbox1.Substring(0, length2 - 1);
input1 = Convert.ToInt32(subDiv);
operation = "/";
break;
case "*":
length2 = length1 + 1;
String subMulty = txtbox1.Substring(0, length2 - 1);
input1 = Convert.ToInt32(subMulty);
operation = "*";
break;
case "=":
switch (operation) {
case "+":
String subAdd2 = txtbox1.Substring(length2, length1
- length2);
input2 = Convert.ToInt32(subAdd2);
total = input1 + input2;
MessageBox.Show("" + total);
break;
case "-":
String subMinus2 = txtbox1.Substring(length2,
length1 - length2);
input2 = Convert.ToInt32(subMinus2);
total = input1 - input2;
MessageBox.Show("" + total);
break;
case "/":
String subDiv2 = txtbox1.Substring(length2, length1
- length2);
input2 = Convert.ToInt32(subDiv2);
total = input1 * input2;
MessageBox.Show("" + total);
break;
case "*":
String subMulty2 = txtbox1.Substring(length2,
length1 - length2);
input2 = Convert.ToInt32(subMulty2);
total = input1 / input2;
MessageBox.Show("" + total);
break;
break;
}
catch (Exception ex)
{
MessageBox.Show("Error");
}
}
}
}