Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

254 Part II Programming Fundamentals



  1. In Solution Explorer, click Form1 .vb, click the View Designer button, and then
    double-click the Spin button.
    The Button1_Click event procedure for the Spin button appears in the Code Editor.

  2. Type the following statements below the Beep() statement in the event procedure:


Wins = Wins + 1
lblWins.Text = "Wins: " & Wins
This part of the program code increments the Wins public variable if a 7 appears
during a spin. The second statement uses the concatenation operator (&) to assign
a string to the lblWins object in the format Wins: X, in which X is the number of wins.
The completed event procedure looks like this:


  1. Click the Save All button on the Standard toolbar to save all your changes to disk.


Save All saves your module changes as well as the changes on your form and in your
event procedures.


  1. Click the Start Debugging button to run the program.

  2. Click the Spin button until you have won a few times.


The Wins label keeps track of your jackpots. Each time you win, it increments the total
by 1. After eight spins, I had the output shown on the following page:

Note The exact number of wins will be different each time you run the program due to
the Randomize statement in the Form1_Load event procedure.
Free download pdf