evaluate-string

 

Evaluate Mathematical Expressions Passed As A String


Evaluate Mathematical Expressions Passed As A String

This code will return 11 from the string "(2 * 3) + 5"


Preparations

Add Microsoft Script Control to your Form. (choose Project->Components,
check the Microsoft Script Control CheckBox and Press OK. Then add the
control to your form).

If you don't have this control, you can download it from
http://msdn.microsoft.com/scripting/


Form Code

Private Sub Form_Load()
'replace the "(2 * 3) + 5" with the string you want to evaluate
MsgBox (ScriptControl1.Eval("(2 * 3) + 5"))
End Sub