Click here to Skip to main content
15,912,665 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Eddy Vluggen22-Apr-15 22:38
professionalEddy Vluggen22-Apr-15 22:38 
QuestionUnsure How to Approach New Personal Project Pin
cyberphreak198121-Apr-15 7:06
cyberphreak198121-Apr-15 7:06 
AnswerRe: Unsure How to Approach New Personal Project Pin
Sascha Lefèvre21-Apr-15 7:24
professionalSascha Lefèvre21-Apr-15 7:24 
GeneralRe: Unsure How to Approach New Personal Project Pin
cyberphreak198121-Apr-15 7:27
cyberphreak198121-Apr-15 7:27 
GeneralRe: Unsure How to Approach New Personal Project Pin
Sascha Lefèvre21-Apr-15 7:36
professionalSascha Lefèvre21-Apr-15 7:36 
GeneralRe: Unsure How to Approach New Personal Project Pin
cyberphreak198121-Apr-15 7:40
cyberphreak198121-Apr-15 7:40 
GeneralRe: Unsure How to Approach New Personal Project Pin
Sascha Lefèvre21-Apr-15 8:34
professionalSascha Lefèvre21-Apr-15 8:34 
QuestionEntity framework : How to get DBcontext.ChangeTracker.Entries(of ???)) for a class known only at runtime Pin
dilkonika20-Apr-15 18:22
dilkonika20-Apr-15 18:22 
AnswerRe: Entity framework : How to get DBcontext.ChangeTracker.Entries(of ???)) for a class known only at runtime Pin
Dave Kreskowiak21-Apr-15 1:50
mveDave Kreskowiak21-Apr-15 1:50 
QuestionContinue to next step in a for..next loop only when the user press a button. Pin
dilkonika18-Apr-15 17:59
dilkonika18-Apr-15 17:59 
AnswerRe: Continue to next step in a for..next loop only when the user press a button. Pin
PIEBALDconsult18-Apr-15 18:52
mvePIEBALDconsult18-Apr-15 18:52 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
dilkonika18-Apr-15 19:01
dilkonika18-Apr-15 19:01 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. PinPopular
PIEBALDconsult18-Apr-15 19:21
mvePIEBALDconsult18-Apr-15 19:21 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
dilkonika18-Apr-15 19:41
dilkonika18-Apr-15 19:41 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
Richard MacCutchan18-Apr-15 21:11
mveRichard MacCutchan18-Apr-15 21:11 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
dilkonika19-Apr-15 4:54
dilkonika19-Apr-15 4:54 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. PinPopular
Dave Kreskowiak19-Apr-15 5:26
mveDave Kreskowiak19-Apr-15 5:26 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
dilkonika19-Apr-15 5:30
dilkonika19-Apr-15 5:30 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
Richard MacCutchan19-Apr-15 6:59
mveRichard MacCutchan19-Apr-15 6:59 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. PinPopular
Dave Kreskowiak19-Apr-15 5:20
mveDave Kreskowiak19-Apr-15 5:20 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
dilkonika19-Apr-15 5:28
dilkonika19-Apr-15 5:28 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
Dave Kreskowiak19-Apr-15 5:35
mveDave Kreskowiak19-Apr-15 5:35 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
dilkonika19-Apr-15 5:54
dilkonika19-Apr-15 5:54 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
Simon_Whale20-Apr-15 3:41
Simon_Whale20-Apr-15 3:41 
AnswerRe: Continue to next step in a for..next loop only when the user press a button. Pin
Richard Deeming20-Apr-15 3:02
mveRichard Deeming20-Apr-15 3:02 
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:
VB.NET
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


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.