Chapter 12 Working with Collections 305
a collection, you can add members to it by using the Add method, and you can examine
the individual members by using a For Each... Next loop.
The following exercise shows you how to create a collection that holds string data
representing the Internet addresses (Uniform Resource Locators, or URLs) that you’ve
recently used while surfing the Web. To connect to the Web, the program will use the Visual
Basic System.Diagnostics.Process.Start method and your default Web browser, a technique
that I first introduced in Chapter 3, “Working with Toolbox Controls .”
Track Internet addresses by using a new collection
- Click the Close Project command on the File menu.
- Create a new Windows Forms Application project named My URL Collection.
- Draw a wide text box object at the top of the form, centered within the form.
- Draw two wide button objects below the text box object on the form, one button
below the other. - Set the following properties for the form and its objects:
Object Property Setting
TextBox1 Text “http://www .microsoft .com/learning/books/”
Button1 Text “Visit Site”
Button2 Text “List Recent Sites”
Form1 Text “URL Collection”
Your form looks like this:
- Click the View Code button in Solution Explorer to display the Code Editor.
- Move the insertion point near the top of the form’s program code, and directly below
the statement Public Class Form1, type the following variable declaration, and then
press ENTER:
Dim URLsVisited As New Collection()