方法一:DataColumn.Expression & DataTable.Compute方法(不支持函数)

DataColumn.Expression:

Dim objData As New DataTable
objData.Columns.Add("a", Type.GetType(Integer))
objData.Columns.Add("b", Type.GetType(Integer))
objData.Columns.Add("c", Type.GetType(Integer))
Dim objCol As DataColumn = _
    objData.Columns.Add("x", Type.GetType(Integer))
objCol.Expression = "a+b*c-2"
Dim objRow As DataRow = DataTable.NewRow()
objRow("a") = 2
objRow("b") = 3
objRow("c") = 4
objData.Rows.Add(objRow)
Console.WriteLine(objData.Rows(0)("x"))


DataTable.Compute:

MessageBox.Show((new DataTable()).Compute("1+2*3/4", "").ToString())


方法二:SQL的方式


方法三:解析

Imports System.Text.RegularExpressions
Public Class Evaluate
    Shared ReadOnly m_instance As New Evaluate()
    ''' 
    ''' 构造函数
    ''' 
    ''' 
    Shared Sub New()
    End Sub
    ''' 
    ''' 获取实例
    ''' 
    ''' 
    ''' 
    ''' 
    Public Shared ReadOnly Property Instance() As Evaluate
        Get
            Return m_instance
        End Get
    End Property
    ' A number is a sequence of digits optionally followed by a dot and
    ' another sequence of digits. The number in parenthesis in order to
    ' define an unnamed group.
    Private Const Num As String = "(\-?\d+\.?\d*)"
    ' List of 1-operand functions.
    Private Const Func1 As String = "(exp|log|log10|abs|sqr|sqrt|sin|cos|tan|asin|acos|atan)"
    ' List of 2-operand functions.
    Private Const Func2 As String = "(atan2)"
    ' List of N-operand functions.
    Private Const FuncN As String = "(min|max)"
    ' List of predefined constants.
    Private Const Constants As String = "(e|pi)"
    Function Eval(ByVal expr As String) As Double
        ' Define one Regex object for each supported operation.
        ' They are outside the loop, so that they are compiled only once.
        ' Binary operations are defined as two numbers with a symbol between them
        ' optionally separated by spaces.
        Dim rePower As New Regex(Num & "\s*(\^)\s*" & Num)
        Dim reAddSub As New Regex(Num & "\s*([-+])\s*" & Num)
        Dim reMulDiv As New Regex(Num & "\s*([*/])\s*" & Num)
        ' These Regex objects resolve call to functions. (Case insensitivity.)
        Dim reFunc1 As New Regex(Func1 & "\(\s*" & Num & "\s*\)", _
            RegexOptions.IgnoreCase)
        Dim reFunc2 As New Regex(Func2 & "\(\s*" & Num & "\s*,\s*" & Num _
            & "\s*\)", RegexOptions.IgnoreCase)
        Dim reFuncN As New Regex(FuncN & "\((\s*" & Num & "\s*,)+\s*" & Num _
            & "\s*\)", RegexOptions.IgnoreCase)
        ' This Regex object drop a + when it follows an operator.
        Dim reSign1 As New Regex("([-+/*^])\s*\+")
        ' This Regex object converts a double minus into a plus.
        Dim reSign2 As New Regex("\-\s*\-")
        ' This Regex object drops parenthesis around a number.
        ' (must not be preceded by an alphanum char (it might be a function name)
        Dim rePar As New Regex("(? ""
            ' Get the argument, replace any comma to space, and convert to double.
            args.Add(CDbl(m.Groups(i).Value.Replace(","c, " "c)))
            i += 1
        Loop
        Dim str As String = ""
        ' function name is 1st group.
        Select Case m.Groups(1).Value.ToUpper
            Case "MIN"
                args.Sort()
                str = args(0).ToString
            Case "MAX"
                args.Sort()
                str = args(args.Count - 1).ToString
        End Select
        Return str
    End Function
End Class


方法四:

http://www.codeproject.com/vb/net/expression_evaluator.asp


参考资料:http://blog.csdn.net/fangxinggood/article/details/5992661