Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Đối với phần mềm để làm việc, bạn cần có một số dữ liệu để làm việc với. Phần mềm này sau đó mất dữ liệu và thao tác nó thành dạng khác. Ví dụ, phần mềm có thể mất cơ sở dữ liệu khách hàng của bạn, được lưu trữ như những người thân và số không trên ổ đĩa cứng máy tính của bạn, | 110 I CHAPTER 4 CONTROLLING THE FLOW lstData.Items.Add intCount.ToString Next End Sub 3. Run the project and click the Backwards for Next Loop button. You should see results like those shown in Figure 4-20. How It Works Let s review. If you use a negative number like -1 For tries to add -1 to the current control value. Adding a negative number has the effect of subtracting the number so intCount goes from its start value of 10 to its new value of 9 and so on until the stop value is reached. _ FIGURE 4-20 The For Each . Next Loop In practical day-to-day work it s unlikely that you ll use For . Next loops as illustrated here. Because of way the .NET Framework typically works you ll usually use a derivative of the For . Next loop called the For Each . . Next loop. In the algorithms you design whenever a loop is necessary you ll have a collection of things to work through and usually this set is expressed as an array. For example you might want to look through all of the files in a folder looking for those that are larger than a particular size. When you ask the .NET Framework for a list of files you are returned an array of strings with each string in that array describing a single file. TRY IT OUT For Each Loop In this Try It Out you ll modify your Loops application so that it returns a list of folders contained at the root of your C drive. 1. Return to the Forms Designer add another Button control to your form and set its Name property to btnForEachLoop and its Text property to For Each Loop. 2. Double-click the button and add the following bolded code to the Click event handler Private Sub btnForEachLoop_Click ByVal sender As System.Object _ ByVal e As System.EventArgs Handles btnForEachLoop.Click Clear the list ClearList List each folder at the root of your C drive For Each strFolder As String In _ My.Computer.FileSystem.GetDirectories C Add the item to the list lstData.Items.Add strFolder Next End Sub Prepared for STEPHEN EISEMAN email REISEMAN071@COMCAST.NET .