0

like evaluate() in VBA, is there any native way of evaluating a simple math expression in vb.net ?

ex :

Dim exp as String
exp = "2+3"
MsgBox(exp)

expecting 5 in message box.

Mahesh Uddama
  • 31
  • 1
  • 9
  • 1
    Programming questions are strictly out of scope here at Super User – Security Hound Jan 20 '21 at 18:38
  • 2
    Does this answer your question? [Evaluate mathematical expression from a string using VB](https://stackoverflow.com/questions/13178637/evaluate-mathematical-expression-from-a-string-using-vb) – GSerg Jan 20 '21 at 19:57
  • 1
    Does this answer your question? [Evaluating string “3*(4+2)” yield int 18](https://stackoverflow.com/q/333737/11683) – GSerg Jan 20 '21 at 19:57
  • thanks, but those are not native answers, correct me if im wrong, i guess there's no way other than importing custom libraries. – Mahesh Uddama Jan 20 '21 at 21:09
  • Yeah, you can do this in strict native code, basically iterate through each character in the string then making a decision to on what o do with it. Maybe will need to working in something like regex to pull the string into numeric and operator components, then you've got the order of operations to consider. Much simpler to reach out to external libraries where all the heavy lifting has already been done – Hursey Jan 21 '21 at 02:36
  • See https://stackoverflow.com/questions/65798782/math-expression-parsing-incorrect-output-when-a-followed-by-a/65802154#65802154 – Mary Jan 21 '21 at 05:05
  • thanks, everyone for the suggestions, so the conclusion is either import 3rd party libraries or write your own either from scratch or adopting what's available. so the simple answer is there's no inbuilt function as its available in VBA. – Mahesh Uddama Jan 21 '21 at 14:53

0 Answers0