tailieunhanh - microsoft visual basic 2008 step by step phần 5

Do các vòng lặp bạn đã làm việc với cho đến nay đã sử dụng từ khóa Trong khi thực hiện một nhóm báo cáo miễn là điều kiện vòng lặp vẫn thật. Với Visual Basic, bạn cũng có thể sử dụng cho đến khi từ khóa trong vòng chu kỳ cho đến khi một điều kiện nhất định là True. | 200 Part II Programming Fundamentals Using the Until Keyword in Do Loops The Do loops you ve worked with so far have used the While keyword to execute a group of statements as long as the loop condition remains True. With Visual Basic you can also use the Until keyword in Do loops to cycle until a certain condition is True. Use the Until keyword at the top or bottom of a Do loop to test a condition just like the While keyword. For example the following Do loop uses the Until keyword to loop repeatedly until the user enters the word Done in the input box Dim InpName As String Do InpName InputBox Enter your name or type Done to quit. If InpName Done Then InpName Loop Until InpName Done As you can see a loop that uses the Until keyword is similar to a loop that uses the While keyword except that the test condition usually contains the opposite operator the equal to operator versus the not equal to operator in this case. If using the Until keyword makes sense to you feel free to use it with test conditions in your Do loops. The Timer Control As we wrap up our consideration of flow control tools and techniques in this chapter you should also consider the benefits of using the Visual Studio Timer control which you can use to execute a group of statements for a specific period of time or at specific intervals. The Timer control is essentially an invisible stopwatch that gives you access to the system clock in your programs. The Timer control can be used like an egg timer to count down from a preset time to cause a delay in a program or to repeat an action at prescribed intervals. Although timer objects aren t visible at run time each timer is associated with an event procedure that runs every time the timer s preset interval has elapsed. You set a timer s interval by using the Interval property and you activate a timer by setting the timer s Enabled property to True. Once a timer is enabled it runs constantly executing its event procedure at the prescribed .

TỪ KHÓA LIÊN QUAN