0% found this document useful (0 votes)
8 views2 pages

Act1 (Substring)

The document describes code for a Windows Forms application that performs basic math operations. It uses a text box to accept numeric input and operators, then parses the input to extract the operands and operation. Based on the operation, it performs the calculation and displays the result.

Uploaded by

Bel Montalban
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Act1 (Substring)

The document describes code for a Windows Forms application that performs basic math operations. It uses a text box to accept numeric input and operators, then parses the input to extract the operands and operation. Based on the operation, it performs the calculation and displays the result.

Uploaded by

Bel Montalban
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

namespace WinFormsApp8

{
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
{

String txtbox1 = textBox1.Text;


int length1 = txtbox1.Length - 1;
String Trigger = txtbox1.Substring(length1);

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");
}

}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy