As the title states, I need to use NCalc in Visual Studio 2010. I am writing a program that will calculate a multi-step math problem in VB, but I'm not quite sure how I'd use NCalc. The user inputs a math problem into a text box, then clicks a button which will tell the program to calculate the answer. I've already added NCalc as a reference, and imported it into the project, I'm just not sure what to do next.
Asked
Active
Viewed 1,836 times
1 Answers
1
You'd need to add, at the top of your file:
using NCalc.Domain;
You could then write something in a button press like:
Expression exp = new Expression(textBox1.Text); // Get the text box text
try
{
object result = exp.Evaluate();
textBox2.Text = result.ToString(); // Place the "answer"
}
catch(EvaluationException e)
{
// This happens if the user enters a "bad" expression
textBox2.Text = "Unable to compute: " + e.Message;
}
For details, see the examples on NCalc's homepage.

Reed Copsey
- 554,122
- 78
- 1,158
- 1,373