We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

On-demand variable value

Thread ID:





94623 May 24,2010 08:52 PM UTC May 26,2010 01:37 PM UTC WinForms 3
Tags: Calculate
Administrator [Syncfusion]
Asked On May 24, 2010 08:52 PM UTC

Is it possible to provide a variable value when CalcQuickBase parses the expression instead of setting a specific list of variables before calling ParseAndCompute. For example, if it finds a variable named "MyVar" during its parse, is it possible to intercept and provide a value?


Arulraj A [Syncfusion]
Replied On May 25, 2010 06:54 AM UTC

Hi Dave,

Thanks for your interest in Syncfusion Products.

Yes. You can give your custom variable name to involve in expression which can then be parsed and computed.

Attached below is a sample for your reference in which the variable name and value for it can be registered through the following code.

//Register a variable name and its value.
string name = this.textBox2.Text; //While using variable name in textBoxes use them within braces
string val = this.textBox3.Text;
if (name.Length > 0)
this.calculator[name] = val;

With this, the registered variable name can be used in expression for computation(For.eg., if “MyVar” is the registered variable, then it can be used in computation something like below:



Administrator [Syncfusion]
Replied On May 25, 2010 09:54 PM UTC


Thanks for the reply, but this is not quite what I'm looking for. I know I can preset variable values before calling ParseAndCompute. What I would like to do is know when ParseAndCompute parses a variable that it cannot find in its list of registered variables so I have an opportunity to supply a value. This would, in my case, be much more efficient than registering every possible variable the user could specify (which is possibly hundreds of variables).


Arulraj A [Syncfusion]
Replied On May 26, 2010 01:37 PM UTC

Hi David,

Thanks for your update.

CalcEngine doesn’t allow user to register the named range on demand(while parsing & computing). It rethrows the exception intentionally inorder to alert user on using bad name in input. If you want to handle the exception then, you can make use of basic try-catch approach at the application level.

private void button1_Click(object sender, EventArgs e)
{ try
string s = calculator.ParseAndCompute(this.textBox1.Text);
this.label3.Text = s;
catch (Exception ex)
{ //shows error if occured and asks the user to register the variable
this.label3.Text = ex.Message;
MessageBox.Show("Error has been occurred. Ensure all variables are registered. If not register the variable and then try");



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon