Hello I am doing a calculator program in VB.net 2010. I am almost done with the program but there is just one problem. The calculator works correctly with entering a number, clicking the operation, and entering another number however when I
click the equals sign it doesn't give the answer. I've looked over the code and can't seem to find the flaw. Could somebody please help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace User_Control_Assignment
{
public partial class User_Control : System.Web.UI.UserControl
{
int addition1,subtraction1,division1,multiplication1,result;
int choice;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Btn1_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn1.Text;
}
protected void Btb2_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btb2.Text;
}
protected void Btn3_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn3.Text;
}
protected void Btn4_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn4.Text;
}
protected void Btn5_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn5.Text;
}
protected void Btn6_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn6.Text;
}
protected void Btn7_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn7.Text;
}
protected void Btn8_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn8.Text;
}
protected void Btn9_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn9.Text;
}
protected void Btn0_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = TextBoxAnswer.Text + Btn0.Text;
}
protected void BtnMult_Click(object sender, EventArgs e)
{
multiplication1 = int.Parse(TextBoxAnswer.Text);
TextBoxAnswer.Text = "";
choice = 4;
}
protected void BtnDiv_Click(object sender, EventArgs e)
{
division1 = int.Parse(TextBoxAnswer.Text);
TextBoxAnswer.Text = "";
choice = 3;
}
protected void Button1_Click(object sender, EventArgs e)
{
addition1 = int.Parse(TextBoxAnswer.Text);
TextBoxAnswer.Text = "";
choice = 1;
}
protected void BtnSub_Click(object sender, EventArgs e)
{
subtraction1 = int.Parse(TextBoxAnswer.Text);
TextBoxAnswer.Text = "";
choice = 2;
}
protected void BtnEquals_Click(object sender, EventArgs e)
{
switch (choice)
{
case 1:
result = addition1 + int.Parse(TextBoxAnswer.Text);
TextBoxAnswer.Text = result.ToString();
break;
case 2:
result = subtraction1 + int.Parse(TextBoxAnswer.Text);
TextBoxAnswer.Text = result.ToString();
break;
case 3:
result = division1 + int.Parse(TextBoxAnswer.Text);
TextBoxAnswer.Text = result.ToString();
break;
case 4:
result = multiplication1 + int.Parse(TextBoxAnswer.Text);
TextBoxAnswer.Text = result.ToString();
break;
}
}
protected void BtnClr_Click(object sender, EventArgs e)
{
TextBoxAnswer.Text = "";
}
}
}