Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running JavaScript in VB? 2

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
Is it possible to execute javascript code, such as functons in a .js file, and get the return values?

...Maybe using WebBrowser Control?

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Check out the Microsoft Script Control.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Works Great!

How about opening the .js file from an http:// location?

Use the Internet Control?

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
OK, using Internet Transfer Control...

I tried using something like:
Inet1.OpenURL "
But how do you get the text?
(with out copying the file to your pc)

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Code:
theText = Inet1.OpenURL("[URL unfurl="true"]http://the.domain.com")[/URL]


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
nevermind... (duh)

Code:
Text = Inet1.OpenURL("[URL unfurl="true"]http://www.somewhere.com/test.js",[/URL] icString)


Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Ooops, guess I posted a few seconds too late...

Thanks anyway...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I've been playing around with the Internet Transfer Control the past week or two, so if you have any questions I might be able to help.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Thanks...
At first I thought you had to Open the URL then get the data...

Then I started looking at the Execute method and it told how to copy a file to your hard drive...

Then I looked at the OpenURL again, and it was a function... (hence the duh)

What do you use Document and Object for...
It looked like they returned the doc name and the full path...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
That's pretty much accurate. Most of the attributes are just parts of the URL that you specify, and as such not particularly useful.

If you decide to use the GET or POST commands for the execute method, be careful. There are crucial synchronization issues (since those commands are asynchronous). There is also one key step missing in the examples about using the POST command to submit data to a form (see if you can figure out what it is). The data will get there, but your CGI (PHP, ASP, etc.) program won't know what to do with it.



Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
BTW... in case anyone else runs accross this thread looking for the same info...

You can do this:
First add these controls:
Microsoft Scripting Control - Inet1
Microsoft Internet Transfer Control - JScript

TextBox - Text1 (Input)
TextBox - Text2 (Output)
CommandButton - Command1

Then some code like this:
Code:
Private Sub Command1_Click()
  JScript.Language = "JavaScript" 'default is vbScript
  JScript.AddCode Inet1.OpenURL("[URL unfurl="true"]http://www.somewhere.com/test.js")[/URL]
  Text2 = JScript.Eval("test('" & Text1 & "')")
End Sub

In this case, might look like this:
Code:
function test(x)
{
  return x * 2;
}

Also... It might be more efficient to move the setup stuff to Form Load...

Code:
Private Sub Form_Load()
  JScript.Language = "JavaScript" 'default is vbScript
  JScript.AddCode Inet1.OpenURL("[URL unfurl="true"]http://www.somewhere.com/test.js")[/URL]
End Sub

Private Sub Command1_Click()
  Text2 = JScript.Eval("test('" & Text1 & "')")
End Sub


Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top