5 Replies - 2499 Views - Last Post: 25 April 2013 - 10:16 AM Rate Topic: -----

#1 pappubeta  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-April 13

execute javascript code in vb.net windowsapplication form

Posted 24 April 2013 - 07:57 AM

hi guys i am trying to execute javascript code in vb.net windowsapplication without using webbrowser control.I am not successful yet.I am getting syntax error.please help me

here is my code:

Public Class Form1
    Dim ss As New MSScriptControl.ScriptControlClass
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ss.AllowUI = True
        ss.Language = "JScript"
        ss.AddCode("<script language=Javascript>" & _
                   "function main(){alert('')})")
        ss.Run("main")
End Sub


Mod edit - Please :code:

Is This A Good Question/Topic? 0
  • +

Replies To: execute javascript code in vb.net windowsapplication form

#2 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,108
  • Joined: 07-September 06

Re: execute javascript code in vb.net windowsapplication form

Posted 24 April 2013 - 08:07 AM

I don't know VB (or .net languages) however, you have an extra closing parenthesis at the end of line 11 (in the string) that shouldn't be there. You also don't have a closing script tag.

What exactly is the syntax error you are getting? That will help us narrow down the problem.
Was This Post Helpful? 0
  • +
  • -

#3 pappubeta  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-April 13

Re: execute javascript code in vb.net windowsapplication form

Posted 24 April 2013 - 09:23 AM

thanks for replying.well it says:
comexceptionunhandled
System.Runtime.InteropServices.COMException{"Syntax error"}
Was This Post Helpful? 0
  • +
  • -

#4 pappubeta  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-April 13

Re: execute javascript code in vb.net windowsapplication form

Posted 25 April 2013 - 08:53 AM

hi guys i am trying to execute javascript code in vb.net windowsapplication without using webbrowser control.I am not successful yet.I am getting syntax error.please help me

here is my code:

Public Class Form1
Dim ss As New MSScriptControl.ScriptControlClass
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ss.AllowUI = True
ss.Language = "JScript"
ss.AddCode("<script language=Javascript>" & _
"function main(){alert('')})")
ss.Run("main")
End Sub


the error is like this:

comexceptionunhandled
System.Runtime.InteropServices.COMException{"Syntax error"}
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,493
  • Joined: 12-June 08

Re: execute javascript code in vb.net windowsapplication form

Posted 25 April 2013 - 08:58 AM

Do not create duplicate topics.. merging.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3220
  • View blog
  • Posts: 10,801
  • Joined: 12-December 12

Re: execute javascript code in vb.net windowsapplication form

Posted 25 April 2013 - 10:16 AM

I haven't been able to get this to run JScript (sorry!) although it works with the VBScript below. However, the JS syntax is corrected from your version.

        'ss.AllowUI = True
        'ss.Language = "VBScript"
        'ss.AddCode("Sub Test" & vbCrLf & "MsgBox(""hello"")" & vbCrLf & "End Sub")
        'ss.Run("Test")

        'ss.AllowUI = True
        'ss.Language = "JScript"
        'ss.ExecuteStatement("(function () { alert(""hello"");})();")

        'or..
        ss.AllowUI = True
        ss.Language = "JScript"
        ss.AddCode("function main() { alert(""hello""); }")
        'ss.AddObject("global", Me)
        ss.Run("main")

The problem is, I believe, that the JS code needs to run in the context of the global or window object, and I'm not sure how to add this context to the ss-object.

So, for your current code, you don't need "<script ..>" etc. (which isn't closed properly anyway) and, as BetaWar has already advised, you have an extra closing round bracket ). Good luck!

This post has been edited by andrewsw: 25 April 2013 - 10:18 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1