Evaluate an expression using the Microsoft Script Control

Evaluate an expression using the Microsoft Script Control

Thanks to COM Interop, you can still use the Microsoft Script Control from VB.NET and any other .NET language. To do so, you must add a reference to the Microsoft Script Control library (from the COM page in the Add Reference dialog box): this action creates a new reference named Interop.MSScriptControl, which enables you to use the Script control with early binding. The following code uses the Eval method to evaluate a math expression from VB.NET:

Dim sc As New MSScriptControl.ScriptControl()' You always need to initialize a language enginesc.Language = "VBScript"' this is the expression - in a real program it will probably be' read from a textbox control Dim expr As String = "12 + 3 * 10"Dim res As Double = sc.Eval(expr)' display the resultConsole.WriteLine("{0} = {1}", expr, res)

See also  Comparing different methods of testing your Infrastructure-as-Code

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist