Results 1 to 2 of 2

Thread: Stopping a Loop with a command button

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Champaign, IL 61820
    Posts
    2

    Post

    I'm not experienced at all with VB but I'm using it on my Senior Design project and I'm kind of stumped. I just want to be able to start a loop with a start button and end it with a stop button. I'm fine with starting the loop - It's just that while the loop is executing, the cmdStop_Click() event cannot occur because the loop is executing. Can someone tell me a)if using a command button click event to stop a loop is possible and b)how would I go about it or where can I see an example of this in action?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use DoEvents in your Loop to Enable the Other Events/Applications to Fire, then use a Module Level Variable to Flag when to Stop, eg.
    Code:
    Private bStop As Boolean
    
    Private Sub Command1_Click()
        bStop = True
    End Sub
    
    Private Sub Form_Activate()
        Dim I As Long
        While Not bStop
            I = I + 1
            Caption = "Looping.. " & I
            DoEvents
        Wend
        Caption = "Loop Canceled"
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

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