In ASP.NET, Evaluate a formula at runtime that is stored in a table

Here's what I'm trying to do:

I have an asp.net page with 3 textboxes on it and one label that will display the answer.  Based on a selection that the user makes I want to be able to get a formula stored in a table that will tell how to calculate a total using the 3 controls as input.

Ex. Formula:  (Val(Textbox1.text) + Val(Textbox2.text) + Val(Textbox3.text)) / 3

The formula will have the real control names in it but the formula will look like above and will be stored in a SQL server table.  If it makes a difference I'm using VB and .NET 3.5.
LVL 1
strauchaAsked:
Who is Participating?
 
Kusala WijayasenaSoftware EngineerCommented:
OK do it like this

1. Refer this article: http://odetocode.com/Code/80.aspx and create your "Evaluator" in VB.NET (just convert the given Evaluator calls to VB.NET using http://www.developerfusion.com/tools/convert/csharp-to-vb/)

2. Write your formula in a way that using parameter placeholders (like: "({0} + {1} + {2}) / 3") and fill the corresponding values using "String.Format"

Dim foumula As String = "({0} + {1} + {2}) / 3"
foumula = String.Format(foumula, TextBox1.Text, TextBox2.Text, TextBox3.Text)

3. No use the "EvalToDouble" or "EvalToInteger" methods in "Evaluator" class that we prepared in step 1 and execute your formula
       
Dim result As Double = EvalToDouble(foumula).ToString()

-Kusala
0
 
SriVaddadiCommented:
What is your question?
0
 
strauchaAuthor Commented:
How do I dynamically evaluate a formula retrieved at runtime?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
samsymonCommented:
use java script for that.
0
 
Kusala WijayasenaSoftware EngineerCommented:
how does your formula looks like ? (can you paste it here ?)

-Kusala
0
 
strauchaAuthor Commented:
Thanks,

    I'll give it a try!
0
 
strauchaAuthor Commented:
Thanks, sorry it took me a little while.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.