[RESOLVED] How to return value from Javascript
Hello ,
I'm trying to execute javascript (through Webbrowser Control) from visual basic 6 and get the result of execution back in visual basic.
The code for execution:
Code:
Private Sub Form_Load()
Dim HmtlPath As String
HmtlPath = (App.Path & "\test.html")
WB.Navigate HmtlPath
End Sub
Private Sub WB_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB.object) And (URL = App.Path & "\test.html") Then
Dim strReturn As String
strReturn = WB.Document.parentWindow.execScript("Test('strTest');", "JavaScript")
Debug.Print strReturn
End If
End Sub
Function Test is executed but does not return a result
How can I get the result from Javascript ?
Re: How to return value from Javascript
Not sure but if you are the author of the javascript then simply write the value to a hidden variable:
<input type="hidden" name="soso">
Re: How to return value from Javascript
Тhank you bazzapr! :)
I am the author of the JavaScript so I can change it.
Your method can be used but I need the function itself to return the result since the execution takes some time.
I found this solution : http://www.vbforums.com/showthread.p...-work-in-vb6.0.
But this is a partial solution because I need to use WebBrowser Control.
So my next question is:
Can I call a function in a Visual Basic from WebBrowser Control?
Re: How to return value from Javascript
I suggest then a loop/timer checking the variable every n seconds/minutes. Remember "DoEvents" in a loop.
Re: How to return value from Javascript
Quote:
Originally Posted by
bazzapr
I suggest then a loop/timer checking the variable every n seconds/minutes. Remember "DoEvents" in a loop.
Yes that is an option but an event-based method is preferable.
Re: How to return value from Javascript
On a Form Put a Command1, Command2, and a WebBrowser control. Copy and Paste the below code to the project
Command1.Caption = Load Html
Command2.Caption = Click Button
Code:
Private Sub Command1_Click()
WebBrowser1.Navigate App.Path & "\JavaScript.html"
End Sub
Private Sub Command2_Click()
WebBrowser1.Document.All("myButton").Click
Results = WebBrowser1.Document.All("a3").Value
MsgBox Results
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim Results As String
If URL = App.Path & "\JavaScript.html" Then
WebBrowser1.Document.All("a1").Value = "Wilson"
WebBrowser1.Document.All("a2").Value = "22402240"
WebBrowser1.Document.All("myButton").Click
MsgBox WebBrowser1.Document.All("a3").Value
End If
End Sub
Copy and Paste below code to a text document and save it as JavaScript.html
Code:
function address()
{
var s = "";
var t = "";
var len = 0;
var i = 0;
var n = 0;
var p = 0;
var code = 0;
var ARG3 = "";
var alphanum="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
s = "Wilson"
t = "22402240"
var address = "r";
//var len, i, n, p, code
len = (s.length > t.length) ? s.length : t.length;
//alert("len = (s.length > t.length) ? s.length : t.length ---> len = " + len);
if(len > 24)
{
len = 24;
}
for(i = 0; i < len; i++)
{
//alert("for(i = 0; i < len; i++) ---> i = " + i);
n = p = 0;
//alert("at n = p = 0 ---> n = " + n + ", p = " + p);
if(i < s.length)
{
n = alphanum.indexOf(s.substring(i, i + 1));
//alert("in if(i < s.length) ---> n = " + n);
}
if(i < t.length)
{
p = alphanum.indexOf(t.substring(i, i + 1));
//alert("in if(i < t.length) ---> p = " + p);
}
if(n < 0)
{
n = 0;
}
if(p < 0)
{
p = 0;
}
code = ((2*n+p) ^ 13) % (alphanum.length - 1);
//alert("code = ((2*n+p) ^ 13) % (alphanum.length - 1) ---> code = " + code);
if(code > 0)
{
address += alphanum.substring(code, code + 1);
//alert("address += alphanum.substring(code, code + 1) ---> address = " + address);
}
}
Arg3 = address;
alert("Arg3.Value = " + Arg3);
//document.write(address); // + "<br />");
}
Run the project
Re: How to return value from Javascript
Quote:
Originally Posted by
vladosfi
Can I call a function in a Visual Basic from WebBrowser Control?
No. You can call a function in a Java Script from VB but not the other way around
Re: How to return value from Javascript
ok i just worked with a tuff javascript button non html code worked or even click i found solution mate
use this in range the (0) from 0 to count upwards try every number from 0 to 1 and on till it clicks
example
wb.Document.Forms(0).submit
test it se if it clicks if not
wb.Document.Forms(1).submit
test it if not
wb.Document.Forms(2).submit
on and on this is 100% javaclicker
extra info
the (0) is the buttons in webbrowser forms so if there is 1-100 buttons in that page your working on try every number it will click them find the 1 you need injoy
Re: How to return value from Javascript