문제

This was a possibility in VB Script by using a script control with the eval function. For example

ScriptControl1.Eval("(10+1.5)") 'Returns 11.5

Is there a way to do this in Vb.Net? The alternative would be to simply split up the string and verify if it is an addition or a subtracting and work from there. I was just wondering if there's already a built in function that I'm not yet aware of.

Thank you

도움이 되었습니까?

해결책

I figured it out. I had to add a COM reference to Microsoft Script control like so: enter image description here

Then I just declare my new variable as a Script Control.

Dim ScriptControl1 As New MSScriptControl.ScriptControl()
ScriptControl1.Eval("(10+1.5)") ' Returns 11.5

Note*

Make sure your Target CPU is at x86! I would receive a COMException if i had it set to Any CPU.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top