View Full Version : How to end unlimited cycle?
obivan
05-15-2009, 03:08 AM
Hi, can you get me help? If I want to end unlimited cycle; how can I do it? This is my cycle.
Private Sub CommandButton1_Click()
For i = 1 To 10
'statement
i = 0
Next
End Sub
Thank a lots
Obivan
Aussiebear
05-15-2009, 03:14 AM
Did your cycle ever start?
Bob Phillips
05-15-2009, 04:28 AM
If you want to just break it, hit the Esc key, maybe more than once, or Ctrl-Break.
If you want an indeterminate number of iterations, use Do...Loop with a condition upon which it exits.
obivan
05-15-2009, 04:55 AM
I would like to end cycle via action of button on sheet.
obivan
Paul_Hossler
05-15-2009, 08:51 AM
Maybe have the 'Stop' button set a flag, and test for that flag within the endless loop?
Paul
Bob Phillips
05-15-2009, 09:27 AM
Public Cancel As Boolean
Private Sub CommandButton1_Click()
Dim i As Long
Cancel = False
For i = 1 To 10
'statement
i = 0
DoEvents
If Cancel Then i = 10
Next
MsgBox "Quit"
End Sub
Private Sub CommandButton2_Click()
Cancel = True
End Sub
obivan
05-16-2009, 03:14 AM
Thanks Paul.
Great solution, thanks for your hepl, xld.
obivan
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.