Solved

JavaScript from VB

Posted on 2003-10-27
2
155 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:fpoyavo
2 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 500 total points
ID: 9628655
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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9629259
i think ....
dim wsh
set wsh=createobject("wscript.shell")
wsh.run "c:\myfile.js"
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now