• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

JavaScript from VB

Hi Experts,

I have JavaScript program in My.JS file located in some folder.
I need to build VB executable that once is started it executes My.JS file.

Thank you.
1 Solution
what does your js file do?

e.g., you might be able to do something like this...

make a reference to microsoft script control under project/references then:

Dim scr As New MSScriptControl.ScriptControl
Dim strJS As String

Dim ff As Integer

ff = FreeFile
Open "C:\documents and settings\bob\my documents\test.js" For Input As #ff
strJS = Input(LOF(ff), ff)
Close (ff)

scr.Language = "javascript"
scr.AddCode strJS

scr.AllowUI = True

'' this is what is in test.js
'function addNumbers(i1, i2) {
'   return i1 + i2;
'function multNumbers(i1, i2) {
'   return i1 * i2;

'' just show the number of procedures we've added
MsgBox scr.Procedures.Count

'' run examples
Dim res As Double
res = scr.Eval("addNumbers(5, 25)")
MsgBox res
res = scr.Eval("multNumbers(5, 25)")
MsgBox res

'' you could also try doing, scr.run strJS

Set scr = Nothing
Richie_SimonettiIT OperationsCommented:
i think ....
dim wsh
set wsh=createobject("wscript.shell")
wsh.run "c:\myfile.js"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now