-
Jun 19th, 2006, 02:56 PM
#1
Thread Starter
Addicted Member
[RESOLVED] [02/03] Question about using VBScript (Eval) in VB.NET
Greetings to all!
I've scoured the web in search of this information; however, it's been in vain. My question is this: is there a way to use the eval function in VB.NET code.
I've had some leads about using Microsoft.VisualBasic.Vsa to execute the code, but it looks to me as if that namespace is better suited to executing VB.NET code on the fly. I've had other leads indicate that I should just compile a JScript dll that contains the function I want to use and call it that way, but some say it's very unreliable.
Does anyone have a concise answer, and possibly some sample code, that would be able to assist me?
Thanks,
Kyjan
-
Jun 19th, 2006, 03:20 PM
#2
Re: [02/03] Question about using VBScript (Eval) in VB.NET
Set a reference in your app to "Microsoft Script Control 1.0" It is under the COM tab in references, not in the .NET tab
then you can do code like this
VB Code:
Dim SC As New MSScriptControl.ScriptControl
Dim Formula As String = "(2+4)*5"
'SET LANGUAGE TO VBSCRIPT
SC.Language = "VBSCRIPT"
'ATTEMPT MATH
Try
Dim Result As Double = Convert.ToDouble(SC.Eval(Formula))
'SHOW THAT IT WAS VALID
MessageBox.Show("Math success, " & Formula & " equals " & Result.ToString)
Catch ex As Exception
'SHOW THAT IT WAS INVALID
MessageBox.Show("Not a valid math formula for a double.")
End Try
-
Jun 19th, 2006, 06:50 PM
#3
Thread Starter
Addicted Member
Re: [02/03] Question about using VBScript (Eval) in VB.NET
Thank you for that. I believe this will be most helpful. Before I close this out though, was I correct in my assumption about the VSA namespace? Can VSA even execute VBScript like this or is it just for compiling VB .NET code on the fly?
Kyjan
-
Jun 19th, 2006, 07:01 PM
#4
Re: [02/03] Question about using VBScript (Eval) in VB.NET
to be honest, I have never used it, so I don't know EXACTLY what it does.
I do know 2 things however..
1) the classes in it belong to microsoft.jscript.dll, which would lead me to believe it was used for javascripting of some sort...
2) the classes are considered obsolete, and while they exist in the 2.0 framework, they have been depreciated, and will most likely be removed from the next version of the framework.
You can see this by going to this link
http://msdn2.microsoft.com/en-us/microsoft.vsa.aspx
and clicking on any of the classes or interfaces.. there is a note in each one that they are considered obsolete and should not be used.
-
Jun 21st, 2006, 09:11 AM
#5
Thread Starter
Addicted Member
Re: [RESOLVED] [02/03] Question about using VBScript (Eval) in VB.NET
A side note and question...
I was reading and found out that I could make an expression evaluator based off of regular expressions. (Of course, this is very complex and comes from Francesco Balena's mind - I won't even attempt to lay claim to it.) My question is, would this be faster than loading up a COM component, or would the overhead of regular expressions create more work?
Kyjan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|