Results 1 to 9 of 9

Thread: [RESOLVED] How to return value from Javascript

Threaded View

  1. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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
    Last edited by jmsrickland; Nov 16th, 2012 at 12:10 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width