Hi I found a neat little way to get the value of an expression using a data table here the code below.
Hope it handy for someone. Comments and suggestions welcome.
vbnet Code:
Option Explicit On
Public Class Form1
Private Function EvalIt(ByVal expression As String) As Decimal
Dim dt As New DataTable()
Dim RetVal As Decimal = 0
'Check for vaild string
If Not String.IsNullOrEmpty(expression) Then
'Use compute to get expression value.
RetVal = dt.Compute(expression, vbNullString)
End If
'Return value.
Return RetVal
End Function
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGo.Click
'Return expresion sum
Dim buff As String = "5+5 * (10+6) * 2"
MessageBox.Show(buff & "=" & EvalIt(buff), "Eval-Demo",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class