Chapter 10 Creating Modules and Procedures 259
Spins to the module. Then you’ll call the HitRate function every time the Spin button is
clicked. You’ll display the results in a new label that you’ll create on the form.
Create a win rate function
- Display the form for the Track Wins program that you’ve been modifying.
The user interface for the slot machine game appears.
- Use the Label control to create a new label below the Wins label. Set the following
properties for the label:
Object Property Setting
Label5 Font
ForeColor
Name
Text
TextAlign
Arial, Bold Italic, 12-point
Red (on Custom tab)
lblRate
“0 .0%”
MiddleCenter
Your form looks similar to the following graphic:
- In Solution Explorer, click the Module1 .vb module, and then click the View Code
button.
The Module1 module appears in the Code Editor. - Type the following public variable declaration below the Public Wins As Short statement:
Public Spins As Short
The module now includes two public variables, Wins and Spins, which will be available
to all the procedures in the project. You’ll use Spins as a counter to keep track of the
number of spins you make.
- Insert a blank line in the module, and then type the following function declaration:
Function HitRate(ByVal Hits As Short, ByVal Tries As Short) As String
Dim Percent As Single