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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problm using webbrowser controle in a loop!

Status
Not open for further replies.

DaviiD2010

Programmer
Apr 25, 2010
12
NL
Hi all . I have list of webpages that need to go in each one of them and a press a print button on each one of them(once i press the print button then the button no longer show as it means i have already send it for print). So I tried doing:

Code:
Dim i As Integer

For i = 0 To List1.Items.Count - 1
   wb.Navigate List1.List(i)

  For Each ele In wb.Document.getelementsbytagname("a")
    If ele.innertext = "Print This page" Then ele.Click
    Next

Next

The above code either freezes my vb6 application or only loads the last page!!Could you guys show me a stable way that my program prints all pages and doesn't freez or skipp printing any pages. Looking forward for replies.Thanks
 
Well after navigation you need to wait for the webbrowser to navigate to the page. Then once it is done loading that page you can do your search for the print button.
[tt]
Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
[/tt]



Good Luck

 
Thanks for your reply. Should i put search for button code after loop or between do eents and loop ? When i put it after loop some time the browser doesn't do click the button untill i refresh the webbrowser controle !! is there any solution for that ?
 
Yes, put the code after the "Loop" statement.

The reason it sometimes doesn't work is simply down to the WebBrowser control. As an alternative you could add your code to the DocumentComplete event of the WebBrowser control and see if that works better.

Finally, you could consider having a timeout after which your code is triggered regardless:
Code:
Timeout = DateAdd("S", 2, Now)
Do While (WebBrowser1.ReadyState <> READYSTATE_COMPLETE)
  DoEvents
  If (Now > TimeOut) Then Exit Do
Loop

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
It should be...

For I
Optional Set Flag For Document Complete Event
Navigate
Wait For navigate
loop
Optional Wait For Flag to be set in Document Complete Event With Time out clause
loop
Search for button to click
loop
next i



Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top