JScript / JScriptEvaluate issue

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
    Dim overhead As String = "10"
        Dim a As Integer
        Dim b As Integer
        Dim c As Integer
        c = 20
        a = 10
        b = 15
        Dim sExpression As String = "a+b"
        Dim oResult As Object
        Try
            Dim myEngine As Microsoft.JScript.Vsa.VsaEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine()
            oResult = Microsoft.JScript.Eval.JScriptEvaluate(sExpression, myEngine)
            MsgBox(oResult)
        Catch ex As Exception
            MsgBox(ex.Message & ex.Source)
        End Try

   end sub


I am getting variable a is not declared. Any one help in this .


Answer this question

JScript / JScriptEvaluate issue

  • Mitch076

    I have used replace function to replace the variable with values.
    so Problem has been fixed.
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim overhead As String = "10"
            Dim a As Integer
            Dim b As Integer
            Dim c As Integer
            c = 20
            a = 10
            b = 15
            Dim sExpression As String = "a+b"
            sExpression = Replace(sExpression, "a", a)
            sExpression = Replace(sExpression, "b", b)
            MsgBox(sExpression)
            Dim oResult As Object

            Try
                Dim myEngine As Microsoft.JScript.Vsa.VsaEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine()
                oResult = Microsoft.JScript.Eval.JScriptEvaluate(sExpression, myEngine)
                MsgBox(oResult)
            Catch ex As Exception
                MsgBox(ex.Message & ex.Source)
            End Try
        End Sub



  • Daniel Lukiw

    Eval.JScriptEvaluate is meant to be used by programs compiled by JSC. It relies on internal data structures to lookup the scope stack, etc from which to resolve identifiers.

    Calls to it from other languages is not supported. The recommended way to do this is to use the VSA interfaces which unfortunately are being obsoleted. See related thread.


  • JScript / JScriptEvaluate issue