|
-
Dec 4th, 2005, 07:11 PM
#1
Thread Starter
Junior Member
[RESOLVED] Waiting for a webpage to load?
Hello!
I have a problem with timers starting before a document finished downloading on a webbrowser.
Thake this as a example:
sub something()
wbBrowser.Refresh
tTimer.Start
end sub
The webbrowser starts refreshing and the timer starts instantly.
What i need is to wait until the document has loaded for the timer to start.
But its not as easy as moving the tTimer.Start to the wbBrowser.DocumentCompleted event, because i need this only on that refresh instance.
I mean only to happen like that when the refresh method is called from inside the sub something.
Did i make my self clear?
Because its a bit hard to explain lol
Well, thanks in advance.
Last edited by juanchoc; Dec 5th, 2005 at 12:27 AM.
-
Dec 4th, 2005, 09:41 PM
#2
Thread Starter
Junior Member
Re: Wait for a DocumentCompleted Event?
Well i tryed this now:
sub something()
wbBrowser.Refresh
Do While wbBrowser.IsBusy = True
Application.DoEvents()
Loop
tTimer.Start
end sub
But with no sucsess.
-
Dec 4th, 2005, 09:43 PM
#3
Re: Wait for a DocumentCompleted Event?
Are you setting IsBusy to False in the Document Complete event?
-
Dec 4th, 2005, 09:49 PM
#4
Thread Starter
Junior Member
Re: Wait for a DocumentCompleted Event?
Hmm no.
Should i?
Sory im kinda new to vb
Btw, IsBusy is readonly, how am i supposed to set it to false?
-
Dec 4th, 2005, 10:05 PM
#5
Re: Wait for a DocumentCompleted Event?
Well, this is from VB6, but you could create your own variable, and after calllng the document, set the value.
VB Code:
blnBusy = True
Do While blnBusy = True
Loop
And then set it to false in the Complete event.
-
Dec 4th, 2005, 11:01 PM
#6
Thread Starter
Junior Member
Re: Wait for a DocumentCompleted Event?
But the problem is that if i use the DocumentCompleted, ill be waiting for all the webpages displayed on my program to be completed.
And what i need i that just on that request, thats been made on that sub.
Got it?
Thats why i thought maybe if i make the program go in a do while loop while the browser is busy, it should "wait" until its idle to continue with my code.
-
Dec 5th, 2005, 12:18 AM
#7
Thread Starter
Junior Member
Re: Wait for a DocumentCompleted Event?
Isnt there any way of stoping code execution until one exact page finished loading?
I mean i can use the DocumentCompleted method but that will afect all of the webpage loading that apears thou all my program, and i just need this to happen on only one sub and anywhere else of my code.
-
Dec 5th, 2005, 12:25 AM
#8
Thread Starter
Junior Member
Re: Wait for a DocumentCompleted Event?
Hmm sory for the posting number lol
Here is the code so its easyer to understand what i mean:
Code:
Private Sub tTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tTimer.Tick
tTimer.Stop()
tClock.Stop()
wbAutoBrowser.ScriptErrorsSuppressed = True
If Refreshed = True Then
DeparseUrls()
Refreshed = False
End If
If j >= 0 Then
wbAutoBrowser.Navigate(Url & results(j))
j = j - 1
tTimer.Interval = ClickWaitInterval
ElseIf j < 0 Then
tTimer.Interval = BrowserRefreshInterval
wbBrowser.Refresh()
Refreshed = True
End If
Do While wbAutoBrowser.IsBusy = True
Application.DoEvents()
Loop
Do While wbBrowser.IsBusy = True
Application.DoEvents()
Loop
dStart = DateTime.Now
tTimer.Start()
tClock.Start()
End Sub
As you can see i tryed to make the application enter the do while loop until the browser is idle, and the continue and start the timers.
But for some strange reason it never enters none of the do while loops!
In theory this would solve my problem, but for some reason it just doesnt work.
So if someone helps me make it work ill be really thankful
-
Dec 5th, 2005, 01:10 AM
#9
Thread Starter
Junior Member
Re: Waiting for a webpage to load?
Well, now i tryed two other thing, but with no succsess...
Code:
Do Until wbAutoBrowser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Do Until wbBrowser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Code:
Do While wbAutoBrowser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Do While wbBrowser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Any sugestions?
-
Dec 5th, 2005, 02:00 AM
#10
Thread Starter
Junior Member
Re: Waiting for a webpage to load?
Well after furter research about the ReadyState property, i tryed this:
Code:
Do Until (wbAutoBrowser.ReadyState = 4) Or (wbAutoBrowser.ReadyState = 0)
Application.DoEvents()
Loop
Do Until (wbBrowser.ReadyState = 4) Or (wbBrowser.ReadyState = 0)
Application.DoEvents()
Loop
And this:
Code:
Do Until (wbAutoBrowser.ReadyState.ToString = "Complete") Or (wbAutoBrowser.ToString = "Uninitialized")
Application.DoEvents()
Loop
Do Until (wbBrowser.ToString = "Complete") Or (wbBrowser.ToString = "Uninitialized")
Application.DoEvents()
Loop
But neither of those two are working...
This is really starting to piss me off lol
I dont see what im doing wrong, can someone point me in the right direction please?
Thanks in advance,
JCC
-
Dec 5th, 2005, 04:08 PM
#11
Thread Starter
Junior Member
Re: Waiting for a webpage to load?
Wow finally solved!
Well after trying a lot of things i got an idea that worked like a charm!
Instead of using the DocumentCompleted method, that wasnt working to me, Im using the ProgressChanged method and i add a If and a boolean. Like this:
Code:
If e.MaximumProgress = e.CurrentProgress Then
AutoBrowserComplete = True
End If
And this on the other sub:
Code:
Do While BrowserComplete = False
Application.DoEvents()
Loop
Please Congratulate me! lol
This was a hard one, and theres no mention of doing it like this on any other site
-
Aug 13th, 2006, 05:07 PM
#12
New Member
Re: [RESOLVED] Waiting for a webpage to load?
I know this is an old post, but anyone who finds this could also try:
VB Code:
Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|