// Method that calculate the result private void BtnCalculate_Click(object sender, EventArgs e) { try { decimal operand1 = Convert.ToDecimal(TxtOperand1.Text); decimal operande2 = Convert.ToDecimal(TxtOperand2.Text); string oper = Convert.ToString(TxtOperator.Text); TxtResult.Text = Calculate(operand1, operande2, oper).ToString(); TxtOperand1.Focus(); } catch (FormatException) { MessageBox.Show("Please enter the valide input", "Enty Error"); } catch (DivideByZeroException) { MessageBox.Show("Please do not divide by 0", "Enty Error"); } catch (OverflowException) { MessageBox.Show("The number entered is out of range!", "Enty Error"); }catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + ex.GetType().ToString() + ex.StackTrace, "Exception"); } }
private void ButnCalc_Click(object sender, EventArgs e) { bool flag; decimal operand1; decimal operand2; decimal answer; //Input Step //Check first input... flag = decimal.TryParse(TxtOperand1.Text, out operand1); if (flag == false) { MessageBox.Show("Enter a whole number", "Input Error"); TxtOperand1.Focus(); return; } // Check second input... flag = decimal.TryParse(txtOperand2.Text, out operand2); if (flag == false) { MessageBox.Show("Enter a whole number", "Input Error"); txtOperand2.Focus(); return; } //Process Step answer = operand1 / operand2; // Display Step txtResult.Text = operand1.ToString() + "divided by" + operand2.ToString() + "equals" + answer.ToString(); txtResult.Visible = true; }
private void BtnCalculate_Click(object sender, EventArgs e) { // get operands and operator from the user decimal operand1 = Convert.ToDecimal(TxtOperand1.Text); decimal operande2 = Convert.ToDecimal(TxtOperand2.Text); string oper = Convert.ToString(TxtOperator.Text); //Calculate the result TxtResult.Text = Calculate(operand1, operande2, oper).ToString(); TxtOperand1.Focus(); }
// Method that calculate the results private void BtnCalculate_Click(object sender, EventArgs e) { try { decimal operand1 = Convert.ToDecimal(TxtOperand1.Text); decimal operande2 = Convert.ToDecimal(TxtOperand2.Text); string oper = Convert.ToString(TxtOperator.Text); if (IsValidatData()) { TxtResult.Text = Calculate(operand1, operande2, oper).ToString(); TxtOperand1.Focus(); } }catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }