Results 1 to 6 of 6

Thread: How do u stop a hectic loop?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    If youre program is based on a loop (a very important one), how can i user stop the loop with the click of a button?

  2. #2
    New Member
    Join Date
    Jan 2001
    Posts
    2
    declare a public variable loopstop as boolean
    public loopstop as boolean

    sub Stop_click()
    loopstop = true
    end sub

    in your loop function write this tag:
    do until loopstop = false
    .
    ..
    ...
    loop

    or

    while loopstop = false
    .
    ..
    wend

    hope this helps

  3. #3
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Sydney Australia
    Posts
    476
    This can be done by geting the loop to check for events at the end of each cycle.

    I wipped up an app that test it.

    Just start a new project put to buttons on it. Command 1 starts the loop. Command2 then stops it and displays the counter value

    Good Luck

    Option Explicit
    Private blnstop As Boolean
    Private lngCounter As Long

    Private Sub Command1_Click()
    blnstop = True
    End Sub

    Private Sub Command2_Click()
    For lngCounter = 0 To 100000000
    If blnstop Then
    MsgBox "Stopped at " & lngCounter
    blnstop = False
    Exit For
    End If
    DoEvents
    Next lngCounter

    End Sub

  4. #4
    New Member
    Join Date
    Jan 2001
    Posts
    2
    sorry
    on that first loop, it should be:
    do until loopstop = TRUE
    loop

  5. #5
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143

    Code:
    Private Sub Command1_Click()
    
       Dim x
       For x = 1 To 100000
          If Me.Check1.Value = 0 Then
             Exit For
          Else
             Print x
          End If
       Next
    End Sub

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    How abt this?

    Code:
    Dim X As Integer
    Do While X < 1000
       X = X + 1
       DoEvents
    Loop

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