Results 1 to 5 of 5

Thread: [RESOLVED] [02/03] Question about using VBScript (Eval) in VB.NET

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Quagmire of programming
    Posts
    165

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    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:
    1. Dim SC As New MSScriptControl.ScriptControl
    2.         Dim Formula As String = "(2+4)*5"
    3.         'SET LANGUAGE TO VBSCRIPT
    4.         SC.Language = "VBSCRIPT"
    5.         'ATTEMPT MATH
    6.         Try
    7.             Dim Result As Double = Convert.ToDouble(SC.Eval(Formula))
    8.             'SHOW THAT IT WAS VALID
    9.             MessageBox.Show("Math success, " & Formula & " equals " & Result.ToString)
    10.         Catch ex As Exception
    11.             'SHOW THAT IT WAS INVALID
    12.             MessageBox.Show("Not a valid math formula for a double.")
    13.         End Try

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Quagmire of programming
    Posts
    165

    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

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Quagmire of programming
    Posts
    165

    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
  •  



Click Here to Expand Forum to Full Width