Com of MS script control

Source: Internet
Author: User

Javascript has an eval method. Anyone who has used it knows its convenience and strength.

In C #, we can also use the COM component to execute JavaScript code.

The following code demonstrates how to use the msscriptcontrol component to execute a mathematical expression:

Msscriptcontrol. scriptcontrolclass SC = new msscriptcontrol. scriptcontrolclass ();
SC. Language = "JavaScript ";
Object OBJ = SC. eval ("1 + 2*(3 + 4 )");
Console. writeline (OBJ );

To use msscriptcontrol, you must reference the COM component Microsoft Script Control 1.0.

Another method is as follows:

// Csc.exe noname1.cs/R: C: \ WINDOWS \ Microsoft. NET \ framework \ v1.1.4322 \ Microsoft. jscript. dll

// Note: the Microsoft. JScript and Microsoft. VSA namespaces must be added.

Public class class1


Static void main (string [] ARGs)


System. Console. writeline ("Hello World ");

String expression = "Var result: Int = 0; Result = 1? \ "Success \": \ "Failure \"";

Microsoft. JScript. VSA. vsaengine VE = Microsoft. JScript. VSA. vsaengine. createengine ();

Console. writeline (Microsoft. JScript. Eval. jscriptevaluate (expression, VE ));



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.