Tuesday, July 15, 2014

Using MS Script control to Evaluate Arithmetic Expressions



The MS Script Control COM component provide simple way to evaluate arithmetic expressions like below.

(2*3)/3
2+3-4
(3*4)+(4+6)/4*5

Add reference of MS Script Control COM component in the project



Following is the sample code to evaluate it.

Public Function EvaluateExpression(ByVal expression As String) As Double

        Dim ScriptControl As New MSScriptControl.ScriptControl

        ScriptControl.Language = "VBSCRIPT"
        Return Convert.ToDouble(ScriptControl.Eval(expression))
     
 End Function

No comments:

Post a Comment