Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Continue to next step in a for..next loop only when the user press a button.

Continue to next step in a for..next loop only when the user press a button.

Scheduled Pinned Locked Moved Visual Basic
csharpquestion
26 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Richard DeemingR Richard Deeming

    This isn't something you would normally do, and prior to .NET 4.5 would be virtually impossible. (You could re-write your code to use a state-machine, but it wouldn't resemble a For loop.) However, if you're using .NET 4.5, you can create a hacky solution using Async / Await:

    Private _buttonClickedSource As TaskCompletionSource(Of Boolean)

    Protected Sub MyButton_Click(ByVal sender As Object, ByVal args As EventArgs) Handles MyButton.Click
    ' Get the TaskCompletionSource that's waiting, if there is one.
    ' Clear the field, since we only want to wait for a single click.
    Dim tcs As TaskCompletionSource(Of Boolean)
    tcs = Interlocked.Exchange(_buttonClickedSource, Nothing)

    ' If we're waiting for a button click, signal that we've receive one:
    If tcs IsNot Nothing Then
        tcs.TrySetResult(True)
    End If
    

    End Sub

    Private Async Function DoYourFunkyThing() As Task
    ...
    For i = 1 To nr1
    ...
    If condition1 Then
    ' Create a new TaskCompletionSource, and enable the button:
    Dim tcs As New TaskCompletionSource(Of Boolean)()
    Interlocked.Exchange(_buttonClickedSource, tcs)
    MyButton.Enabled = True

            ' Wait for the button to be clicked:
            Await tcs.Task
            
            ' Disable the button:
            MyButton.Enabled = False
        End If
    Next
    

    End Function

    The compiler will re-write this method to use a state machine, but you can still write your code as if it was a For loop. Async (Visual Basic)[^] Asynchronous Programming with Async and Await (C# and Visual Basic)[^]


    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

    D Offline
    D Offline
    dilkonika
    wrote on last edited by
    #17

    Thanks to all for your down Votes. It's seems that those who doesn't have the idea how to resolve the problem , attack the question. Sorry friend what do you want , to ask : " ... It's true that 1+1=2 ?" It's sure that for this question exist a solution ( even prior to .NET 4.5 ) ( for sure , it's not me that found the solution , because I don't pretend to be a high level professional ). But I will not post here the solution. Maybe some of those that have down voted , try to find the answer , because someone that pretend to have a professional level , should show this with an answer not with a down vote.

    D Richard DeemingR 2 Replies Last reply
    0
    • D dilkonika

      Thanks to all for your down Votes. It's seems that those who doesn't have the idea how to resolve the problem , attack the question. Sorry friend what do you want , to ask : " ... It's true that 1+1=2 ?" It's sure that for this question exist a solution ( even prior to .NET 4.5 ) ( for sure , it's not me that found the solution , because I don't pretend to be a high level professional ). But I will not post here the solution. Maybe some of those that have down voted , try to find the answer , because someone that pretend to have a professional level , should show this with an answer not with a down vote.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #18

      Yeah, about the reputation...

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • D dilkonika

        Thanks to all for your down Votes. It's seems that those who doesn't have the idea how to resolve the problem , attack the question. Sorry friend what do you want , to ask : " ... It's true that 1+1=2 ?" It's sure that for this question exist a solution ( even prior to .NET 4.5 ) ( for sure , it's not me that found the solution , because I don't pretend to be a high level professional ). But I will not post here the solution. Maybe some of those that have down voted , try to find the answer , because someone that pretend to have a professional level , should show this with an answer not with a down vote.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #19

        And why have you posted this abusive response to my message, when I've tried to help you? :mad: Your account is currently on 8 "abusive/troll" votes. Two more, and you'll be kicked off the site.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        D 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          And why have you posted this abusive response to my message, when I've tried to help you? :mad: Your account is currently on 8 "abusive/troll" votes. Two more, and you'll be kicked off the site.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          D Offline
          D Offline
          dilkonika
          wrote on last edited by
          #20

          and what is the abusive part of my post ? If you are one of them that down voted , well , sometimes the truth is hard to accept.:confused:

          Richard DeemingR L 2 Replies Last reply
          0
          • D dilkonika

            and what is the abusive part of my post ? If you are one of them that down voted , well , sometimes the truth is hard to accept.:confused:

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #21

            I posted a genuine answer to your question. You replied with a message complaining about down-votes, and stating that you found an answer elsewhere, but you're not going to share it with us because none of us are "professional" enough. And you can't see the abusive part of that? :doh:


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            D 1 Reply Last reply
            0
            • D dilkonika

              and what is the abusive part of my post ? If you are one of them that down voted , well , sometimes the truth is hard to accept.:confused:

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #22

              dilkonika wrote:

              and what is the abusive part of my post ?

              The part where you tell a professional that is trying to help you that he should not have posted an answer. It is saying you want explanation in words, not code - and demand code five minutes later.

              dilkonika wrote:

              sometimes the truth is hard to accept.:confused:

              Yes, a recurring theme.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

              S 1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                I posted a genuine answer to your question. You replied with a message complaining about down-votes, and stating that you found an answer elsewhere, but you're not going to share it with us because none of us are "professional" enough. And you can't see the abusive part of that? :doh:


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                D Offline
                D Offline
                dilkonika
                wrote on last edited by
                #23

                Maybe was a mistake from me that I posted my replies to your message. My replies was intend to be a general replies to all of those that have down voted. Because I think each down vote should have an argumentation. And I found the answer elsewhere ( it is not my solution ) , but I don't post here only for those that have down voted. ( if you are one of them , this is for you too). The reason is that I think that when someone doesn't know the solution , attack the question. For these people I thing that they aren't professional. Instead of simply down vote a question : 1) Find a solution 2) Ignore the question 3) Say " I'm sorry I don't know " 4) Down vote , but with arguments why this question has problems.

                L 1 Reply Last reply
                0
                • D dilkonika

                  Maybe was a mistake from me that I posted my replies to your message. My replies was intend to be a general replies to all of those that have down voted. Because I think each down vote should have an argumentation. And I found the answer elsewhere ( it is not my solution ) , but I don't post here only for those that have down voted. ( if you are one of them , this is for you too). The reason is that I think that when someone doesn't know the solution , attack the question. For these people I thing that they aren't professional. Instead of simply down vote a question : 1) Find a solution 2) Ignore the question 3) Say " I'm sorry I don't know " 4) Down vote , but with arguments why this question has problems.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #24

                  dilkonika wrote:

                  My replies was intend to be a general replies to all of those that have down voted.

                  That'd be me.

                  dilkonika wrote:

                  And I found the answer elsewhere ( it is not my solution ) , but I don't post here only for those that have down voted.

                  Not a downvote, but an abuse-flagging. It is not something that is flagged on a question, but on an account. Read his post again.

                  dilkonika wrote:

                  The reason is that I think that when someone doesn't know the solution , attack the question.

                  More likely cause would be being rude against volunteers.

                  dilkonika wrote:

                  For these people I thing that they aren't professional.

                  This is spare time, you should not be expecting a business-treatment.

                  dilkonika wrote:

                  Instead of simply down vote a question :

                  Demands are hardly going to work. There's some basic rules for the forum as a sticky on top of each page. I think it is worded correctly. Instead of making demands, try kindness.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                  1 Reply Last reply
                  0
                  • L Lost User

                    dilkonika wrote:

                    and what is the abusive part of my post ?

                    The part where you tell a professional that is trying to help you that he should not have posted an answer. It is saying you want explanation in words, not code - and demand code five minutes later.

                    dilkonika wrote:

                    sometimes the truth is hard to accept.:confused:

                    Yes, a recurring theme.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                    S Offline
                    S Offline
                    Sascha Lefevre
                    wrote on last edited by
                    #25

                    Are you as well reminded of a certain member by a(nother?) member posting a couple of questions here recently?...

                    If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                    L 1 Reply Last reply
                    0
                    • S Sascha Lefevre

                      Are you as well reminded of a certain member by a(nother?) member posting a couple of questions here recently?...

                      If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #26

                      Yes, but it appears to be in a different tone than this thread. Time will tell :)

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups