Results 1 to 6 of 6

Thread: Unresponsive Form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Posts
    30
    I am having trouble with a for/next loop and a form.

    When I click a command button, a for next loop pings a series of ip address specified by the user. This works fine, but while the loop is running, the form is unresponsive to mouse clicks, gets stuck behind other widows ect. until the loop finishes. Then the form returns to normal.

    I added a form1.refresh to the loop, so now it redraws itself if I Move a window over it, but it still gets stuck behind other windows, and will not redraw itself on top, until the loop is finished.

    Could someone please explain why this is happening?
    The Loop will typically take 4 1/2 minutes to run, during this time it looks like the app is locked execpt for the progress bar moving on the form.

    Thank You

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Code:
    For a = 1 to 1000
       DoEvents   <---Add This 
       'Other code
    Next a
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I may be wrong here, but to the best of my knowledge a DoEvents statement in a For Loop does nothing.

    I personally only use for loops for small things.
    If there's anything that'll be big or take a long time I do something like this :

    Code:
    i = 0
    Do Until i = 1000
        DoEvents
        i = i + 1
        'Do Something
    Loop
    - jamie
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Posts
    30

    Do Events worked

    Thanks for the help. This is working much better

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    It does plenderj! The For Next will 'lock' just like other loops.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Sorry about that, right you are.
    I remember trying it before, but it never worked.
    I think it was VB5 I was trying it on ....

    Oh well
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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