JavaScript from VB

fpoyavo
fpoyavo used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
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
i think ....
dim wsh
set wsh=createobject("wscript.shell")
wsh.run "c:\myfile.js"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial