One Step Further: Adding to a Program


One Step Further: Adding to a Program

You can restart Visual Studio at any time and work on a programming project you've stored on disk. You'll restart Visual Studio now and add a Randomize statement to the Lucky Seven program.

Reload Lucky Seven

  1. On the Windows taskbar, click Start, point to All Programs, point to Microsoft Visual Studio 2005, and then click the Microsoft Visual Studio 2005 program icon.

    A list of the projects that you've most recently worked on appears on the Visual Studio Start Page. Because you just finished working with Lucky Seven, the MyLucky7 project should be first on the list.

  2. Click the MyLucky7 link to open the Lucky Seven project.

    The Lucky Seven program opens, and the MyLucky7 form appears. (If you don't see the form, click Form1.vb in Solution Explorer, and then click the View Designer button.)

    Now you'll add the Randomize statement to the Form_Load procedure, a special procedure that is associated with the form and that is executed each time the program is started.

  3. Double-click the form (not one of the objects) to display the Form_Load procedure.

    The Form_Load procedure appears in the Code Editor, as shown here:

    graphic

  4. Type Randomize, and then press the Down Arrow key.

    The Randomize statement is added to the program and will be executed each time the program starts. Randomize uses the system clock to create a truly random starting point, or seed, for the Rnd statement used in the Button1_Click procedure. As I mentioned earlier, without the Randomize statement, the Lucky Seven program produces the same string of random spins every time you restart the program. With Randomize in place, the program spins randomly every time it runs, and the numbers don't follow a recognizable pattern.

  5. Run the new version of Lucky Seven, and then save the project. If you plan to use the new version a lot, you might want to create a new .exe file, too.

  6. When you're finished, click Close Project on the File menu.

    The files associated with the Lucky Seven program are closed.


Chapter 2 Quick Reference

To

Do this

Create a user interface

Use Toolbox controls to place objects on your form, and then set the necessary properties. Resize the form and the objects as appropriate.

Move an object

Position the mouse pointer over the object until the four-headed arrow appears, and then drag the object.

Resize an object

Click the object to select it, and then drag the resize handle attached to the part of the object you want to resize.

Delete an object

Click the object, and then press the Delete key.

Open the Code Editor

Double-click an object on the form (or the form itself).

or

Select a form or a module in Solution Explorer, and then click the View Code button.

Write program code

Type Visual Basic program statements associated with objects in the Code Editor.

Save a program

On the File menu, click the Save All command.

or

Click the Save All button on the Standard toolbar.

Save a form file

Make sure the form is open, and then on the File menu, click the Save command.

or

Click the Save button on the Standard toolbar.

Create an .exe file

On the Build menu, click the Build or Rebuild command.

Deploy an application by using ClickOnce technology

Click the Publish command on the Build menu, and then use the Publish wizard to specify the location and settings for the application.

Reload a project

On the File menu, click the Open Project command.

or

On the File menu, point to Recent Projects, and then click the desired project.

or

Click the project in the recent projects list on the Visual Studio Start Page.