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:


  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.

Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
Year: 2003
Pages: 168
Similar book on Amazon © 2008-2017.
If you may any questions please contact us: