Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluating Expressions at run time

Status
Not open for further replies.

varshan09

Programmer
Oct 28, 2003
45
0
0
IN
We are having a table where we are storing some values and an asociated operator with each value. We will be using the value and the operator along with a comparison value and would like to know the result at run time. For e.g. let's say the entry in the table is:
30 >=
and the comparison value is 40. We would like to know the result of the following expression at run time
(30 >= 40)

Is there any way of achieveing this. In javascript I could use eval() function to evaluate the expression. Is there anything similar in VB.Net.
 
Just make a case statement.

Pull the operator and value

Code:
Public Function Compare(ByVal MyValue as Integer) AS Boolean
    dim Value as integer, Operator as String 
    Value = DataRow("Value")
    Operator = cstr(DataRow("Operator")

    Select Case Operator
         Case ">"
             Return Value > MyValue
         Case "<"
             Return Value < MyValue
         Case "<="
             Return Value <= MyValue
         ...
         ...
         ...
     End Select
End Function

As far as I can tell, there's nothing built in. However, just search for "Evaluate Mathematical Expression Runtime VB.NET" in Google and you'll see varioius classes that can parse much more complex expressions than what I just did.

--NipsMG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top