Pausing Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HP

    Pausing Code

    Hi,

    Does anyone know if it is possible to force the code to pause during every
    iteration of a FOR ... NEXT loop, and wait for the user to click a command
    button for the next iteration. I need to let the user step through the
    looping at his/her own pace.

    Any help would be greatly appreciated.

    h.


  • Larry Serflaten

    #2
    Re: Pausing Code

    "HP" <nospam@nospam. com.au> wrote[color=blue]
    > Hi,
    >
    > Does anyone know if it is possible to force the code to pause during every
    > iteration of a FOR ... NEXT loop, and wait for the user to click a command
    > button for the next iteration. I need to let the user step through the
    > looping at his/her own pace.
    >
    > Any help would be greatly appreciated.[/color]


    Don't use a For/Next loop. Make the counter a larger scope so that
    you can save it between calls.

    LFS





    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

    Comment

    • Auric__

      #3
      Re: Pausing Code

      "...And the next sign of the Apocalypse will be..."
      *****
      On Tue, 20 Jan 2004 07:27:12 +1000, HP wrote:
      [color=blue]
      >Hi,
      >
      >Does anyone know if it is possible to force the code to pause during every
      >iteration of a FOR ... NEXT loop, and wait for the user to click a command
      >button for the next iteration. I need to let the user step through the
      >looping at his/her own pace.
      >
      >Any help would be greatly appreciated.
      >
      >h.[/color]

      If it was me, I'd have the button change a shared variable to indicate
      that it's been clicked, and have your code check for that, like this:
      Private wasClicked as Boolean

      Sub myLoop()
      For n = 1 To 9
      Do Until wasClicked
      DoEvents
      Loop
      wasClicked = False
      'your code here
      Next
      End Sub

      Sub Button1_Click()
      wasClicked = True
      End Sub

      Alternately, you could write the code to run when the button was
      clicked, and keep track of where it was using a static variable, like
      this:
      Sub Button1_Click()
      Static x As Integer
      x = x + 1 'replace 1 with the low end of your loop
      If x <= 9 Then 'replace 9 with the high end of your loop
      'your code here
      End If
      End Sub
      ....but then you'd have to figure out how to reinitialize the "loop" if
      you ran it more than once.

      Comment

      • Larry Serflaten

        #4
        Re: Pausing Code

        "Auric__" <not.my.real@em ail.address> wrote in
        [color=blue]
        > If it was me, I'd have the button change a shared variable to indicate
        > that it's been clicked, and have your code check for that, like this:
        > Private wasClicked as Boolean
        >
        > Sub myLoop()
        > For n = 1 To 9
        > Do Until wasClicked
        > DoEvents
        > Loop
        > wasClicked = False
        > 'your code here
        > Next
        > End Sub
        >
        > Sub Button1_Click()
        > wasClicked = True
        > End Sub[/color]


        Go to 4, then close the app.... (if you can <g>)

        LFS




        -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
        http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
        -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

        Comment

        • Auric__

          #5
          Re: Pausing Code

          "...And the next sign of the Apocalypse will be..."
          *****
          On Mon, 19 Jan 2004 17:35:37 -0600, Larry Serflaten wrote:
          [color=blue]
          >"Auric__" <not.my.real@em ail.address> wrote in
          >[color=green]
          >> If it was me, I'd have the button change a shared variable to indicate
          >> that it's been clicked, and have your code check for that, like this:[/color][/color]

          <snip code>
          [color=blue]
          >Go to 4, then close the app.... (if you can <g>)
          >
          >LFS[/color]

          Feh. Who ever closes apps before they're totally done? <g> It's a simple
          matter to add another flag to watch for the form closing. Or just add
          "End" to the form's Unload event.

          But on reflection, you're right - my second snippet (which is pretty
          much the same as what you suggested all of 10 minutes earlier, but I
          missed until later) is probably better.

          Comment

          • Murray

            #6
            Re: Pausing Code

            All that HP is looking for is a way to pause at each iteration of a For/Next
            Loop.
            What's wrong with -
            For i% = 1 To 50
            'Do your stuff
            Answer = MsgBox("This is iteration #" & Format$(i%, "##") & Chr$(13) &
            "Press OK to continue, Cancel to end", vbOKCancel + vbDefaultButton 1, "Any
            title")
            If Answer = vbCancel Then Exit For
            Next i%


            "HP" <nospam@nospam. com.au> wrote in message
            news:400c4bb4$0 $14485$afc38c87 @news.optusnet. com.au...[color=blue]
            > Hi,
            >
            > Does anyone know if it is possible to force the code to pause during every
            > iteration of a FOR ... NEXT loop, and wait for the user to click a command
            > button for the next iteration. I need to let the user step through the
            > looping at his/her own pace.
            >
            > Any help would be greatly appreciated.
            >
            > h.
            >
            >[/color]


            Comment

            • HP

              #7
              Re: Pausing Code

              Thanks Guys ... Much appreciated ... You have given me a few good options, I
              will have a think about which one suits me best!

              Cheers,

              hp.

              "HP" <nospam@nospam. com.au> wrote in message
              news:400c4bb4$0 $14485$afc38c87 @news.optusnet. com.au...[color=blue]
              > Hi,
              >
              > Does anyone know if it is possible to force the code to pause during every
              > iteration of a FOR ... NEXT loop, and wait for the user to click a command
              > button for the next iteration. I need to let the user step through the
              > looping at his/her own pace.
              >
              > Any help would be greatly appreciated.
              >
              > h.
              >
              >[/color]


              Comment

              Working...