Results 1 to 6 of 6

Thread: For Loop Randomly Freezes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    For Loop Randomly Freezes

    VB Code:
    1. For i = 0 To 9999
    2.    
    3.     strHTML =    'get the source.  i know it gets the source correctly even when it freezes
    4.  
    5.     If InStrB(1, strHTML, "this") <> 0 Then
    6.         x = x + 1
    7.         Label2.Caption = x
    8.     ElseIf InStrB(1, strHTML, "or this") <> 0 Then
    9.         x = x + 1
    10.         Label2.Caption = x
    11.     ElseIf InStrB(1, strHTML, "thisthis") <> 0 Then
    12.         x = x + 1
    13.         Label2.Caption = x
    14.     Else
    15.         add_log strHTML
    16.         lstlog.AddItem Time & " Found it"
    17.     End If
    18.     DoEvents
    19.     Sleep 10
    20.     Pause (1)
    21. 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
    Last edited by cx323; Apr 28th, 2006 at 09:08 PM.

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    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

  4. #4

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: For Loop Randomly Freezes

    VB Code:
    1. Private Function add_log(ByVal msg As String)
    2.     Open App.Path & "\Log.txt" For Append As #1
    3.     Print #1, msg
    4.     Close #1
    5.     add_log = msg
    6. End Function

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: For Loop Randomly Freezes

    VB Code:
    1. Sleep 10
    2. Pause (1)

    What is this all about?

Posting Permissions

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



Click Here to Expand Forum to Full Width