/// <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; } } }
/// <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; } } } }
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(); } } }