Failing loop

cah1982

Registered User.
Local time
Today, 23:22
Joined
May 7, 2005
Messages
27
Right, this has kind of got me baffled.

I run my code and it loops fine most of time, it can process upto a few thousand records then gets stuck here, no fail messages

cTime = Now() + TimeValue("00:00:5")
Do While ie.Busy = True Or ie.ReadyState <> 4 Or Now() > cTime
' MsgBox (Now() > cTime)
'MsgBox (IE.ReadyState)
'MsgBox (Iie.Busy)
'IE.Visible = True
DoEvents
Loop


Now if I remove the ' to show the message box`s,it shows

True
4
True

which normally results in it gets past, but odd time it just gets stuck there, but still displays True, 4 , True, but loops back in this

Any ideas?
 
This is typical of attempting a connection to a website.
What exactly are you trying to do? What i the issue /message/problem you have?

I have seen in the past,

Code:
Sub WaitForBrowser(Browser As SHDocVw.InternetExplorer, Optional TimeOut As Single = 10)
      Dim MyTime As Single

10        MyTime = Timer
20        Do While Browser.Busy Or (Timer <= MyTime + TimeOut)
30            DoEvents
40        Loop

          ' if browser still busy after timeout, give up
50        If Browser.Busy Then
60            MsgBox "I waited for " & Timer - MyTime & " seconds, but browser still busy" & vbCrLf & _
                     "I give up now!"
70            End
80        End If
............
 
It basically, goes to web page enters a consignment number, then returns the recipients name and date signed for package.

It all works had it do 3000 consignments in one go, then other times a few hundred.

There is loops/catch errors so if theres a fail it shows the error message etc

but it seems to get stuck in that loop but when u show the message box it shows the correct values to exit the loop. grrr
 
just put in ie.visible, and it shows the ie window, fully loaded as per msg box`s, but yet doesn't come out of the loop

its as if its forgotten the do while, but you can still use other buttons on the form and use, so access etc hasn't crashed
 
Try pausing the code ctrl-Break, then look at you variable values.
 
Try pausing the code ctrl-Break, then look at you variable values.

ive looked at the bits in the while condition and they all show values which should escape it,
 
It is possible an Ie check is failing when the loop tests but then shows True when it subsequently writes the message box.

Put a Watch on the values you need to monitor. Watches include a condition and initiate a break when that condition is met. That will catch it in action rather than testing the gate after the horse already escaped.
 
I did the watch thing, they all show the values that normally get it out of the loop, its bizarre

Processed 2000 records first time and few hundred on second attempt
 
Do While ie.Busy = True Or ie.ReadyState <> 4 Or Now() > cTime

how do these show values that break the loop
the first and third are true?

as soon as now exceeds time you are stuck basically. - so you get 5 seconds processing?

maybe you want "ands" not "ors"
 
cheeers gemma, s should it be

Do While IE.busy = True And Now() < cTime Or IE.ReadyState <> 4 And Now() < cTime

i basically want it to exit the loop when either condition is met, so if now is greater then ctime, or either ie is completed
 
I don't know to be honest.

I think jdraw had it right. he is obviously familiar with the principle

why do you need ie.busy AND ie.readystate?
 
cheeers gemma, s should it be

Do While IE.busy = True And Now() < cTime Or IE.ReadyState <> 4 And Now() < cTime

i basically want it to exit the loop when either condition is met, so if now is greater then ctime, or either ie is completed

You may want to try this. This should ensure you get out of the loop on the timer if page still not loaded or still busy:

Code:
Do While IE.busy = True Or IE.ReadyState <> 4 
     '
     ' 
     If Now() < cTime Then Exit Do
     Loop

Good luck !
Jiri
 

Users who are viewing this thread

Back
Top Bottom