Is there any similar control/FCL in . NET like Script Control?

J

John

Hi,

Is there any similar control/FCL in . NET like Script Control that can eval a piece of VBScript code or Javascript Code?

Thanks!
John
 
T

Tom Shelton

This is a multi-part message in MIME format.

------=_NextPart_000_00B1_01C98ECA.F5CD4BE0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,=20

Is there any similar control/FCL in . NET like Script Control that can =
eval a piece of VBScript code or Javascript Code?

Thanks!
John

John,

While there is nothing like the script control, there are a couple of options
that might do what you want...

The first, is to use the code dom to generate and compile code. Once
compiled, you can load and execute the methods from the assembly.

If your dealing with jscript, then you can actually use the jscript.net eval
method to execute snipits of javascript. I actually, have an article on my
blog that describes using this method to evaluate mathmatical expressions at
runtime - but, it actually can be used to run arbitrary snipts of jscript :)

http://tom-shelton.net/?p=63

If neither of these methods do exactly what you want, you can actually still
use the script control from you vb.net code via com interop.
 
J

Jie Wang [MSFT]

Hi John,

Thank you for posting!

I second to Tom's opinion. Using CodeDOM to generate source code for an
expression then compile it is a possible approach. Here is the online
document link in case you're interested in this technique:
http://msdn.microsoft.com/en-us/library/650ax5cx.aspx.

If you want to use the good old Script Control anyway, you can import
msscript.ocx as a reference into your project, then use the code like the
following piece to eval the script expression:

Dim sc As New ScriptControl
sc.Language = "VBScript"

Dim expr As String = "Log(10) + 4 ^ 0.5"
Dim r As Double = CDbl(sc.Eval(expr))

Console.WriteLine("{0} = {1}", expr, r)

The result will be:
Log(10) + 4 ^ 0.5 = 4.30258509299405

However, using COM interop to make use of the Script Control also brings
potential problems. For example, you might have to compile your code
explicitly as targeting x86 CPU, otherwise, on x64 Windows your code might
fail if there is no 64bit version of Script Control.

Making use of JScript.NET as Tom mentioned is a "cleaner" approach - you
don't have to worry about COM interop issues, and yet you can have a very
similar and straight forward solution.

Looking forward, Microsoft will implement Dynamic Language Runtime (DLR)
into future versions of .NET, which could be a long term solution for your
next version of application. Here is the Wikipedia page for this topic:
http://en.wikipedia.org/wiki/Dynamic_Language_Runtime.

Please let me know if you have any further questions regarding this topic.

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jie Wang [MSFT]

Hello John,

Would you mind letting us know if your problem has been sovled or not? If
you have any other questions or concerns, please don't hesitate to let me
know. I'll be happy to help.

Best regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top