Archive for February, 2010

Executing VBScript Function from an ASP.NET 2.0 Class

Wednesday, February 24th, 2010

1. download window script control 1.o from

http://www.microsoft.com/downloads/details.aspx?FamilyId=D7E31492-2595-49E6-8C02-1426FEC693AC&displaylang=en

2. Go to Website > Add Reference…  Found the Microsoft Script control, added it, and it’s working.

Learn from http://forums.asp.net/p/1078702/1591861.aspx#1591861

3. Code:

Imports Microsoft.VisualBasic
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub submit(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles gs.Click
Response.Redirect(”http://www.google.com/search?q=” & q.Text & “&Submit+now.x=10&Submit+now.y=7&Submit+now=Submit+now&res=”)
End Sub
Protected Sub Bcal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Bcal.Click
Dim sc As New MSScriptControl.ScriptControl()
‘ You always need to initialize a language engine
sc.Language = “VBScript”
‘ this is the expression – in a real program it will probably be
‘ read from a textbox control
‘Dim expr As String = “12 + 3 * 10″
Dim resu As Double = sc.Eval(q.Text)
res.Text = resu.ToString
End Sub
End Class

Imports Microsoft.VisualBasic

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub submit(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles gs.Click

Response.Redirect(”http://www.google.com/search?q=” & q.Text & “&Submit+now.x=10&Submit+now.y=7&Submit+now=Submit+now&res=”)

End Sub

Protected Sub Bcal_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Bcal.Click

Dim sc As New MSScriptControl.ScriptControl()

‘ You always need to initialize a language engine

sc.Language = “VBScript”

‘ this is the expression – in a real program it will probably be  read from a textbox control

‘ Dim expr As String = “12 + 3 * 10″

Dim resu As Double = sc.Eval(q.Text)

res.Text = resu.ToString

End Sub

End Class