[RESOLVED] How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters-VBForums
Results 1 to 11 of 11

Thread: [RESOLVED] How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Resolved [RESOLVED] How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    PD EDIT: My version of VB is Visual Basic 6.0 from Excel.

    Hello, this is not like last question where I did not care with or without parameters:
    How to Call a JavaScript function From Visual Basic 6 with or without parameters

    This time I do need to send the parameters I want.

    In the web page I have many of this two lines with unic ID in this cases 1234,777 (just examples):
    PHP Code:
    <a onmouseout="hideBoxInfo();" onmouseover="BigBoxInfo(1234);" href="DialogPageInfo.php?Box_id=57485">
    <
    a onmouseout="hideBoxInfo();" onmouseover="BigBoxInfo(777);" href="DialogPageInfo.php?Box_id=42837"
    I can call the onmouseover with:
    Code:
        k = 0
        For Each ele In IE.Document.GetElementsByTagName("a")
            If ele.onmouseout = "hideBoxInfo();" <> "" Then
                k = k + 1
                If k >= 14 Then
                    Cells(k, 1) = ele.onmouseover
                    Call ele.fireevent("onmouseover")
                End If
            End If
        Next
    In the Innertext the function looks something like this:
    Code:
    function BigBoxInfo(id) 
    {
      ....SourceCode blabla....
    }
    ======================================================
    It would be great if I could just call function BigBoxInfo(ID=Any ID I want), instead of having to search for the page where the HTML is compiled with the tags <a onmouseover="BigBoxInfo(ID I want);"> so I am able to fireevent.

    I have tried firebug to change the ID, and onmouse over it loads the information even if I am not on the page where that ID form is showing.

    I have also search for information where some people says its imposible to call a javascript function from VB6 and instead, they use:
    RegisterClientScriptBlock
    RegisterStartupScript
    I can swear I have been nearly 4 hours trying to find some code that works with Visual Basic 6 but so far no luck.

    It would be great if I could just add lines and lines with the IDs I want and the only fire the events
    <a onmouseover="BigBoxInfo(1);">
    <a onmouseover="BigBoxInfo(2);">
    <a onmouseover="BigBoxInfo(....);">
    <a onmouseover="BigBoxInfo(9999);">
    <a onmouseover="BigBoxInfo(N);">

    , or even better, just directly call the function witout the HTML need.

    Thanks and sorry for the big post
    Last edited by Verzulsan; May 24th, 2011 at 06:42 AM.

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Re: How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    I keep searching with no luck.

    Why is it so hard to just make a call to that from VB 6.0?
    If I call the value of OnMouseOver, it returns me this:
    Code:
    function onmouseover()
    {
    BigBoxInfo(4564);
    }
    I have tried with next line, no results.

    ele.fireevent "function onmouseover()" & Chr(10) & "{" & Chr(10) & "BigBoxInfo(4564);" & Chr(10) & "}"

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,420

    Re: How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    Well for one thing what you have is not VB 6.0 at all, but Excel VBA.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Re: How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    Yes, I use VBA from excel, I thought it didnt matter because when I select "About" from menu, I get the version and it says 6.3, i Thought it was 6.0


    Is there any chance I can call javascript functions from VBA?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,192

    Re: How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    Thread moved from 'VB6' forum to the 'Office Development/VBA' forum (while VBA and VB6 have some similarities, they are not the same thing)

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    20,003

    Re: How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    Is there any chance I can call javascript functions from VBA?
    while you were in the wrong forum the same code will work (or not)

    i think you would need to go with execscript and pass the parameter (correctly)

    i will test later, when i have some time to make up a webpage with javascript function to call
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Re: How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    si_the_geek, sorry, I didn't know it was so different, since I use VBA, every single code I find of VB6 it had always worked in excel, some of them adding library from references, my mistake.

    Quote Originally Posted by westconn1 View Post
    ...i think you would need to go with execscript and pass the parameter (correctly)

    i will test later, when i have some time to make up a webpage with javascript function to call
    westconn1, it would be great if you make it work, I'm anxious to get your results. I'll be making some more research and I'll come here on any progress I make.

    Thanks for your help.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    20,003

    Re: How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    i tested this, where wb is an instance of internet explorer

    vb Code:
    1. wb.document.parentwindow.execscript "mytest('123')"
    the function mytest
    Code:
    function mytest(inp) {
    alert(inp);
    }
    msgbox with 123 shows
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Re: How to Call a JavaScript function From Visual Basic 6 WITH wanted parameters

    Quote Originally Posted by westconn1 View Post
    vb Code:
    1. wb.document.parentwindow.execscript "mytest('123')"
    the function mytest
    Code:
    function mytest(inp) {
    alert(inp);
    }
    msgbox with 123 shows
    westconn1, you are a genius. It works like a charm:
    Code:
    IE.Document.parentwindow.execscript "BigBoxInfo('1234')"
    Thanks a lot; you don't know how many work and time of coding you have saved me.
    Thanks again

    I mark the post as solved.

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    20,003

    Re: [RESOLVED] How to Call a JavaScript function From Visual Basic 6 WITH wanted para

    i am sure, that is the same as i posted in your previous thread
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    15

    Re: [RESOLVED] How to Call a JavaScript function From Visual Basic 6 WITH wanted para

    That is true; I just saw it again...
    wb.document.parentwindow.execscript "loadmax('tree')"
    I remember trying that in many combinations and didn't work :S, I was probably calling the wrong function, anyways it works now.

    PD: I tried to give you reputation in "Rate this post" but the forum won't let me give you more reputation since last thread.
    Thanks again westconn1, I own you a big one
    Last edited by Verzulsan; May 28th, 2011 at 06:26 AM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.