+ Reply to Thread
Results 1 to 2 of 2

CTRL +BREAK

Hybrid View

  1. #1
    Moiz, ABAC UK
    Guest

    CTRL +BREAK

    Is there a way to create a button that stops a series of "iterations" - the
    equivalent of CTRL+BREAK

    how?

    Moiz



  2. #2
    K Dales
    Guest

    RE: CTRL +BREAK

    Here is a simple example:

    Public Interrupt As Boolean

    Public Sub TEST()
    Interrupt = False
    For i = 1 To 30000
    If Interrupt Then Exit For
    Range("A1").Value = i
    DoEvents
    Next i
    End Sub

    Sub Button1_Click()
    Interrupt = True
    End Sub

    Key elements:
    - Public variable that gets set to a particular value when button pressed
    - In your sub containing the loop you need to "preset" the value of the
    variable so the loop will run
    - Important! Include a DoEvents statement inside the loop. Without it the
    button press will not be detected until the loop ends.
    - Have some way of terminating the loop when the value of the public
    variable gets set by the button. Above I use an Exit For statement, but
    personally I don't like that approach (I am an old-time structured
    programmer). I prefer to do a While loop in the form of:
    While .... And Not Interrupt.
    ' loop code
    Wend
    -
    --
    - K Dales


    "Moiz, ABAC UK" wrote:

    > Is there a way to create a button that stops a series of "iterations" - the
    > equivalent of CTRL+BREAK
    >
    > how?
    >
    > Moiz
    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1