HI everyone! Please help! HOw to make a loop wait until a button is click...??

In which Language u want it ...

just use a input Way or try out to show Message Box... that will help u out

In VB.net....but i want the user fill out the form then thay click that button and the next form appear so the loop will continue.

oki ... js make an object of the next form nd write obj.showDialouge() in between that loop
then it becomes what u want

post ur code ere ,,,,

if put the form between the loop it just run until the loop is end... i want it to run in order...actually not a form but a groupbox...i want to loop that group box...when the user fill out info in that groupbox, they click the next groupbox will appear for they to fill out...but the loop just run up to the final groupbox...Here is the code:

iNumberOfPassengers = CInt(txtAdult.Text)
 Dim gboNextPassenger(iNumberOfPassengers) As GroupBox
 Dim iCounter As Integer = 1
 For iCounter = 1 To iNumberOfPassengers 
            
            gboNextPassenger(iCounter) = New GroupBox

End If

here is an idea sample code , not tested and not the best solution.

'lets take for loop . now do this
dim buttonclick as boolean = false
dim i as integer

for i = 0 to 100 
while buttonclick= false

end while
next
 'and use this code at the button click

buttonclick = true

may be this will solve your prob , but as i said this is not the ideal solution and i not tested it yet.so if it will show some prob then please dont mind.
Regards

Bro! it runs like forever....

hello i tested this code at my end and its working properly , please check this out

'import this .
import.system.form.application
'lets work with for-loop . now do this
dim buttonclick as boolean = false
dim i as integer

for i = 0 to 100 
while buttonclick= false
 doevents() 'it will let the computer works and you can perform any other action.
end while
next
 'and use this code at the button click

buttonclick = true

this will solve your prob , if your prob is solved then please mark this thread solved , and dont forget to vote me up :)

Regards

I can put the key import anywhere, where do we put the import

at the top of your form , at very top of your form ,

it appear error...red underline.....:(

I try to do ike what u said but the loop doesn't stop...it constantly create new groopbox...here is the code....

iNumberOfPassengers = CInt(txtAdult.Text) + CInt(txtChildren.Text)

  Dim gboNextPassenger(iNumberOfPassengers) As GroupBox

        Dim bIsClicked As Boolean = False

        Dim iCounter As Integer = 1

 For iCounter = 1 To iNumberOfPassengers

 While bIsClicked = False
                Application.DoEvents()

                gboNextPassenger(iCounter) = New GroupBox
 End While

        Next iCounter

     
        bIsClicked = True

The idea of event driven systems is to avoid polling/idling loops. Polling/idling uses CPU cycles unnecessarily and slows down anything else that may be running at the same time. One way to avoid this when you need to process several forms in succession and in a specific order is to daisy-chain the forms. When the user completes a form, either by clicking an "OK" or "NEXT" button, that form can call up the next form as part of its Close event handler. Another possibility is to create an array of form references and display them modally in a loop as in

Private myforms() as Form = {
   frmForm1,
   frmForm2,
   frmForm3
}

.
.
.

    For Each frm As Form In myforms
        If frm.ShowDialog() <> Windows.Forms.DialogResult.OK Then
            MsgBox("processing interrupted")
            Exit For
        End If
    Next

The second approach makes it easier to rearrange the order in which the forms are displayed as it decouples the forms.

A third approach is to use state transition logic in which you have a global state variable which determines which form is the next one to be displayed. The next form (or state) would be determined by the completion status of the previous form. This approach would be useful when the order of the forms is not fixed. There would be two possible "final" states - one in which all of the forms had been successfully completed, and one in which the user bailed out (or errored out).

The idea of event driven systems is to avoid polling/idling loops. Polling/idling uses CPU cycles unnecessarily and slows down anything else that may be running at the same time. One way to avoid this when you need to process several forms in succession and in a specific order is to daisy-chain the forms. When the user completes a form, either by clicking an "OK" or "NEXT" button, that form can call up the next form as part of its Close event handler. Another possibility is to create an array of form references and display them modally in a loop as in

Private myforms() as Form = {
   frmForm1,
   frmForm2,
   frmForm3
}

.
.
.
    For Each frm As Form In myforms
        If frm.ShowDialog() <> Windows.Forms.DialogResult.OK Then
            MsgBox("processing interrupted")
            Exit For
        End If
    Next

The second approach makes it easier to rearrange the order in which the forms are displayed as it decouples the forms.

A third approach is to use state transition logic in which you have a global state variable which determines which form is the next one to be displayed. The next form (or state) would be determined by the completion status of the previous form. This approach would be useful when the order of the forms is not fixed. There would be two possible "final" states - one in which all of the forms had been successfully completed, and one in which the user bailed out (or errored out).

Can i apply the second approach for for the group box??? cause actually i loop a groupbox which contains other controls(label, radiobutton, textbox)

You'll have to be clearer as to what you want to do.

i loop a groupbox which contains other controls(label, radiobutton, textbox)

You can do anything you want in a loop. I can't offer a suggestion unless I have a clear idea what you are doing. The last suggestion was on how to display a sequence of forms without using a wait loop. That was a clearly defined goal. If you can be more specific I'd be glad to help.

Ok! here is it.
in the top of a form I ask user for how many passengers will go with them.

iNumberOfPassengers as Integer = CInt(txtNumberOfPassengers.Text)

And then in the bottom of that form, i make a new groupbox which will ask each passengers what are their name, title, age....(contains many label and textbox, combo box for user to put info in)

Dim gboPassengerDetails(iNumberOfPassenger) as new Groupbox

i take iNumberOfPAssenger as a parmeter of that groupbox array because i want to loop that groupbox the number of time which is equal to iNumberOfPassenger. if their is 2 passenger i will loop that 2 time to ask the first passenger and then the second..if 3 passengers ..i will loop 3...etc..

However...the loop can not pause for user to input data in...if there are 3 passengers...groupbox(1), groupbox(2) and groupbox(3) will appear without any pause between to input data in.

For iCounter = 1 To iNumberOfPassengers 

   gboPassengerDetails(iCounter) = New GroupBox

Next icounter

the problem now is how to make the loop pause at the position 3 in the line...so user can input data for each passenger? hic hic

You'll have to be clearer as to what you want to do.

You can do anything you want in a loop. I can't offer a suggestion unless I have a clear idea what you are doing. The last suggestion was on how to display a sequence of forms without using a wait loop. That was a clearly defined goal. If you can be more specific I'd be glad to help.

if u still feel unclear i will give u my project to have a clear look...it's very short..don't worry!

Usually, when you want to pause until a user has entered data, you display a modal form with the input fields. Because the form is displayed as modal, the calling form waits until it closes. You can always create a basic input form and dynamically create textboxes for the input data. If you don't want to create the controls at run time, and you know the maximum number of text entry fields then you can create them at design time and hide/show them as required.

Or, your input form could have one set of text boxes for data entry, and the user clicks an ADD button which adds the new fields to an array or collection. The only way to exit the form (other than CANCEL) is to enter the required number of items.

Again, no polling loop required.

No polling loop required.

If you want to zip and post the project I can have a look.

Solution 1: i have no idea about modal form you are talking about
solution 2: i am using this, i create textbox and combo box dynamically at run time in a groupbox which is dynamic itself...
solution 3: we can not use this, it's far long from what i want to do...

hey let me say 1 thing .. what u want acctually is ... that a loop start nd complete 1 cycle nd then stops then after pression button .. it starts again and then stops then press buttopn to start and in every cycle a grp box hav to generate ... is that oki ..

hey let me say 1 thing .. what u want acctually is ... that a loop start nd complete 1 cycle nd then stops then after pression button .. it starts again and then stops then press buttopn to start and in every cycle a grp box hav to generate ... is that oki ..

It's just pause for user to fill out that groupbox and then continue with counter+1 ...not stop...

oki wait

It's just pause for user to fill out that groupbox and then continue with counter+1 ...not stop...

please check this attached file , hope this will solve your prob.


Regards

Thanks you everyone...i am new to vb.net... i am using a java head to do vb.net stuff...actually, it's very easy...thank you everyone support me...the project is done!

if done then please mark this thread as solved .

Regards

The attached project demonstrates how to do looped input without a loop (or polling). It requires some work to make it a little more robust (preventing duplicate entries, for example).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.