コード例 #1
0
ファイル: Calculator.cs プロジェクト: IUS-CS/JavaTheHutt
        /// <summary>
        /// Performs a function evaluation on the math string that has been built prior to this method call
        /// </summary>
        /// <param name="sender">The sender that sent the event argument</param>
        /// <param name="e">The event argument</param>
        private void buttonEquals_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(resultBox.Text))
            {
                try
                {
                    FunctionEval function = new FunctionEval();

                    double result_number = function.Evaluate(result);
                    result         = result_number.ToString();
                    resultBox.Text = result;
                }
                catch (Exception ex)
                {
                    resultBox.Text = "Error: " + ex;
                }
            }
        }
コード例 #2
0
ファイル: Calculator.cs プロジェクト: IUS-CS/JavaTheHutt
        /// <summary>
        /// Performs a function evaluation on the math string that has been built prior to this method call
        /// </summary>
        /// <param name="sender">The sender that sent the event argument</param>
        /// <param name="e">The event argument</param>
        private void resultBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                result = resultBox.Text;

                if (!string.IsNullOrEmpty(result))
                {
                    try
                    {
                        FunctionEval function = new FunctionEval();

                        double result_number = function.Evaluate(result);
                        resultBox.Text = result_number.ToString();
                    }
                    catch (Exception ex)
                    {
                        resultBox.Text = "Error: " + ex;
                    }
                }
            }
        }
コード例 #3
0
        private void buttonEval_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(FunctionBox.Text))
            {
                labelResult.Text = "Function box is empty";
            }
            else if (string.IsNullOrEmpty(VarBox.Text))
            {
                labelResult.Text = "Variable box is empty";
            }
            else
            {
                try
                {
                    FunctionEval func = new FunctionEval();

                    labelResult.Text = "f(" + VarBox.Text + ") = " + func.Evaluate(FunctionBox.Text, Double.Parse(VarBox.Text));
                }
                catch (Exception ex)
                {
                    labelResult.Text = ex.ToString();
                }
            }
        }