#QUESTION: Wait for condition?
#QUESTION: Wait for condition?
#QUESTION: Wait for condition?
#QUESTION: Wait for condition?
#QUESTION: Wait for condition?
#QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition?
#QUESTION: Wait for condition? #QUESTION: Wait for condition?
#QUESTION: Wait for condition?
Go Back  Xtreme Visual Basic Talk > > > #QUESTION: Wait for condition?


Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-2010, 09:28 AM
Ambassa Ambassa is offline
Newcomer
 
Join Date: May 2010
Posts: 4
Default #QUESTION: Wait for condition?


While running a function, I want it to pause until a button is clicked, and then continue again.
I've tried using the while loop(cont is the variable that becomes true when a button is clicked):
Code:
Do While cont = False
            Loop
However that crashes my program since it basically is an infinite loop.
I've also tried the sleep function, but that won't work either since it stops my entire program (thus the user can't click the button)

Any help is greatly appreciated guys! I'm desperate Gratte

Btw, I'm coding in visual basic 2008.
Reply With Quote
  #2  
Old 05-09-2010, 12:12 PM
shekoasinger shekoasinger is offline
Freshman
 
Join Date: May 2010
Location: The Netherlands
Posts: 46
Talking Help

This code ur using.. I dont really know what else ur using. But Im trying to give u an option. Hope it helps.

Code:
Do While cont = False
            Loop
Well U can also do it like this
Code:
dim abc as integer = o
Do While cont = False
If abc = 0 then
loop
end if
U should then write in ur button:
Code:
abc = 1
as abc wont be 0 anymore, it will stop looping lolz.. To start looping again make sure abc = 0.

Hope this helps
Reply With Quote
  #3  
Old 05-09-2010, 01:02 PM
Ambassa Ambassa is offline
Newcomer
 
Join Date: May 2010
Posts: 4
Default

Quote:
Originally Posted by shekoasinger View Post
This code ur using.. I dont really know what else ur using. But Im trying to give u an option. Hope it helps.

Code:
Do While cont = False
            Loop
Well U can also do it like this
Code:
dim abc as integer = o
Do While cont = False
If abc = 0 then
loop
end if
U should then write in ur button:
Code:
abc = 1
as abc wont be 0 anymore, it will stop looping lolz.. To start looping again make sure abc = 0.

Hope this helps
This doesn't solve my problem; it's still an infinite loop.
Thanks for trying though
Reply With Quote
  #4  
Old 05-09-2010, 01:32 PM
AtmaWeapon's Avatar
AtmaWeapon#QUESTION: Wait for condition? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

There are ways, but it can get complicated fast if you really want it as described. My guess is you want a series of events like this:

Code:
* User does something to start the processing.
* Something happens that needs the user's attention; you display a message.
* When the user clicks a button, the process continues.
The easiest way to pull it off is to use a message box as a dialog box. For example, suppose you have a loop that does something 100 times, but if an error happens you want to prompt the user to see if they want to continue or not. The MessageBox.Show() function returns a DialogResult value that tells you what button they pushed. Here's an example with hand-wavy magic parts you'll have to fill in yourself:
Code:
For i As Integer = 0 To 100
    Dim errorHappened As Boolean = ProcessData(i)
    If errorHappened Then
        Dim result As DialogResult = MessageBox.Show("An error happened.  Continue?", _
                                                     "", _
                                                     MessageBoxButtons.YesNo)
        If result = DialogResult.No Then
            Exit For
        End If
    End If
Next
Maybe that's not appropriate for your UI. In this case, you need to get a little more fancy. Make your method smart enough to be able to start working in the middle of the process rather than do the whole thing. When it encounters a program, set up the UI the way you want it then exit the method. When the user clicks the button, start the method where it left off. This won't work well with a Function because they have to return a value; it'd be best to use a Sub at this point. For example:
Code:
Private _lastIndex As Integer
Private _intermediateResult As Integer
Private _result As Integer

' Stores result in _result if completed successfully.
Sub ProcessData(ByVal startIndex As Integer)
    For i As Integer = startIndex To 100
        If i = 25 Then
            _lastIndex = i
            DisplayError(25)
            Exit Sub
        End If

        _intermediateResult += i
    Next

    _result = _intermediateResult
End Sub

Sub RestartButton_OnClick(...) Handles RestartButton.Click
    ProcessData(_lastIndex + 1)
End Sub
In this example, the number 25 can't be processed for some reason. The process presumably starts at 0. When it encounters a number it can't handle, it stores the index it was processing in _lastIndex, calls a magic DisplayError() that updates the UI to display an error, and quits data processing. When the user clicks the restart button, it resumes data processing at the next index. This can get messy if done improperly; I would normally prefer the MessageBox-based solution.

There are a few other techniques that could accomplish this goal. Most of them are stupid, confusing, and wasteful. The rest are so complicated they aren't worth it. I could probably tailor a more specific and elegant example, but you didn't provide much detail so I have to be general.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
#QUESTION: Wait for condition?
#QUESTION: Wait for condition?
#QUESTION: Wait for condition? #QUESTION: Wait for condition?
#QUESTION: Wait for condition?
#QUESTION: Wait for condition?
#QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition? #QUESTION: Wait for condition?
#QUESTION: Wait for condition?
#QUESTION: Wait for condition?
 
#QUESTION: Wait for condition?
#QUESTION: Wait for condition?
 
-->