Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Add variables

$
0
0
Imports System.Xml
Imports Microsoft.ClearScript

Public Class WebForm1
Inherits System.Web.UI.Page

Private xml As XmlDocument = New XmlDocument
Private documentid As Integer = New Integer
Private cs_engine As Windows.JScriptEngine = New Windows.JScriptEngine

Public Sub Initialize()
    cs_engine.AddHostObject("xml", xml)
    cs_engine.AddHostObject("me", Me)

    Try
        cs_engine.Execute("xml.LoadXml('<sales id=""123""/>');")
        cs_engine.Execute("me.documentid = me.documentid + 1;")

    Catch e As Microsoft.ClearScript.ScriptEngineException
        Response.Write(e.GetBaseException)
    End Try

    If xml.InnerXml.ToString <> "" Then
        Response.Write(xml.SelectSingleNode("//sales").Attributes.GetNamedItem("id").InnerText & "<BR><BR>")
    Else
        Response.Write("No XML Detected!<br><br>")
    End If

    Response.Write(documentid)
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
End Class

Loading an XML object or database connection in clearscript with AddObject method is no problem. But how can I add a integer or string variable so when I manipulate it in script I can refer it outside script in VB or vice versa ?

Viewing all articles
Browse latest Browse all 2297

Trending Articles