For Loop Randomly Freezes
VB Code:
For i = 0 To 9999
strHTML = 'get the source. i know it gets the source correctly even when it freezes
If InStrB(1, strHTML, "this") <> 0 Then
x = x + 1
Label2.Caption = x
ElseIf InStrB(1, strHTML, "or this") <> 0 Then
x = x + 1
Label2.Caption = x
ElseIf InStrB(1, strHTML, "thisthis") <> 0 Then
x = x + 1
Label2.Caption = x
Else
add_log strHTML
lstlog.AddItem Time & " Found it"
End If
DoEvents
Sleep 10
Pause (1)
Next i
I'm not sure why it's freezing. It's frozen anywhere from the 2nd time to the 38th. Also if you could tell me why it uses 100% of the cpu even with a pause adn DoEvents that would be great. Thanks for any help
Re: For Loop Randomly Freezes
Don't worry about how much CPU time your loop is using. Other processes are allocated time as needed by the OS.
If you don't need to see the caption change every iteration you can remove the sleep and pause and only call DoEvents every 20th iteration or so.
Re: For Loop Randomly Freezes
thanks for the help, the cpu usage problem is gone, but it still freezes, i've had to go up to 877 but it still froze
Re: For Loop Randomly Freezes
What does add_log look like?
Re: For Loop Randomly Freezes
VB Code:
Private Function add_log(ByVal msg As String)
Open App.Path & "\Log.txt" For Append As #1
Print #1, msg
Close #1
add_log = msg
End Function
Re: For Loop Randomly Freezes