# [vb] Do until a button is clicked?



## fongweibin (May 5, 2011)

hi there im a beginner in vb, im doing a traffic light system right now. i have build the code, but don't know how to loop the whole thing. The condition is like the following:
-There are three traffic lights, each goes and another follows after the previous one turns red.
-im now trying "do until (exitbutton.selected)" ..."loop" ---> doesnt return a value, i know there is a mistake here
the loop should continue running until user click on the exit button.
anyone can help me? im using a timer by the way, and i have declared the variable "count" to count the timer. should i add "count = 0" at the last part of the loop in order to let the count starts from zero again?

sorry i know ive explained quite poorly. Please feel free to ask more thank you


----------



## DaBeers (Oct 31, 2008)

There are just a few things you need to do to make a timer work.

Drop a timer on the form.

Set the increment.

```
[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]
Timer1.Interval = 100
[/SIZE][/FONT][/SIZE][/FONT]
```
(1000 = 1 second)

Tell it to start.

```
[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]
Timer1.Start()
[/SIZE][/FONT][/SIZE][/FONT]
```
Then you can use the Timer1.Ticks event to run code at your selected interval.

GL


----------



## centauricw (Jun 26, 2010)

You should be using the Button.Click event to capture the exit button click. It can then set a variable to show the exit button has been clicked. You watch this variable in your loop and exit the loop when the variable is set.


----------

