コード例 #1
0
        // 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");
            }
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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();
        }
コード例 #4
0
ファイル: FrmMain.cs プロジェクト: ktchoko1/Cis-3309
        // 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());
            }
        }