Hello, below is an equals button method for a calculator that was made in Visual Studio 2017 that is in C#.
Can anyone help me to append it and get the history.text, put it into a string variable, so that I can add the string to a ListBox to store the history.
protected void ButtonEquals_Click(object sender, EventArgs e)
{
if (calc_result.Value == string.Empty)
{ // User must enter a value for the button to function correctly.
Response.Write("<script>alert('No Value is given.')</script>");
}
else
{
ViewState["Value2"] = calc_result.Value;
calc_result.Value = string.Empty;
try
{
if ((string)ViewState["Operation"] == "Addition")
{
calc_result.Value = _Calculate.Add(Convert.ToInt32(ViewState["Value1"]), Convert.ToInt32(ViewState["Value2"])).ToString();
}
else if ((string)ViewState["Operation"] == "Subtraction")
{
calc_result.Value = _Calculate.Subtract(Convert.ToInt32(ViewState["Value1"]), Convert.ToInt32(ViewState["Value2"])).ToString();
}
else if ((string)ViewState["Operation"] == "Multiplication")
{
calc_result.Value = _Calculate.Multiply(Convert.ToInt32(ViewState["Value1"]), Convert.ToInt32(ViewState["Value2"])).ToString();
}
else if ((string)ViewState["Operation"] == "Division")
{
calc_result.Value = _Calculate.Divide(Convert.ToInt32(ViewState["Value1"]), Convert.ToInt32(ViewState["Value2"])).ToString();
}
else if ((string)ViewState["Operation"] == "Percentage")
{
calc_result.Value = _Calculate.Percentage(Convert.ToInt32(ViewState["Value1"]), Convert.ToInt32(ViewState["Value2"])).ToString();
}
else Response.Write("<script>alert('No Operation was recorded.')</script>");
}
catch (FormatException)
{
Response.Write("<script>alert('Bad Input Format.')</script>");
}
}
}