Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top