Option Explicit
Private dblValue1 As Double, dblValue2 As Double, strNameP1 As String, strNameP2 As String, dblValue3 As Double, dblValue4 As Double, dblTotal1 As Double, dblTotal2 As Double, dblX As Double
Private Sub Form_Load()
Randomize 'Randomizes numbers spun
End Sub
Private Sub cmdPlayer1Name_Click()
strNameP1 = InputBox("Enter player one's name and then press ok.") 'Creates an inputbox for player 1 to enter his or her name
lblPlayer1.Caption = "Player one's name: " & strNameP1 'Displays player 1's name
cmdPlayer1Name.Visible = False 'Removes the option to enter player 1's name again
cmdPlayer2Name.Visible = True 'Gives player 2 the option to enter their name
lblPlayer1.Visible = True 'Displays the name player 1 entered
End Sub
Private Sub cmdPlayer2Name_Click()
strNameP2 = InputBox("Enter player two's name and then press ok.") 'Creates an inputbox for player 2 to enter his or her name
lblPlayer2.Caption = "Player two's name: " & strNameP2 'Displays player 2's name
cmdPlayer2Name.Visible = False 'Removes the option to enter player 2's name again
lblPlayer2.Visible = True 'Displays the name player 2 entered
MsgBox "Spin the wheel by pressing the spin button, " & strNameP1 & "." 'Tells player 1 what to do after entering names
cmdSpin1A.Visible = True 'Gives player 1 the option to spin
lblTurn.Caption = "It's " & strNameP1 & "'s turn!" 'Displays player 1's name on the who's turn is it label
End Sub
Private Sub cmdStart_Click()
imgBob.Visible = False
MsgBox "Please enter both players' names by clicking the appropriate buttons." 'Allows players to enter their names
cmdStart.Visible = False 'Removes start button from screen so it can't be pressed again
cmdPlayer1Name.Visible = True 'Displays Enter player 1's name button on screen
End Sub
Private Sub cmdSpin1A_Click()
dblValue2 = 0 'Sets intValue 2 for spin 2 to 0 in case player 1 only spins once
dblX = Int(Rnd * 20) 'Generates amount of first spin
dblValue1 = 0.05 * dblX + 0.05
MsgBox "You have a value of " & (dblValue1 * 100) & " cents for your first spin." 'Message box telling player 1 his or her first spin value
lblValue1.Caption = "Value of first spin: " & (dblValue1 * 100) 'Displays value of first spin by player 1 on a label
lblValue1.Visible = True 'Makes the first spin value for player 1 visible
dblTotal1 = (dblValue1 + dblValue2) 'Calculates the total for both spins; for only one spin, the total is intValue1
lblValue3.Caption = "Total value of both spins: " & (dblTotal1 * 100) & " cents." 'Displays the total value of both spins
lblValue3.Visible = True
If dblValue1 <= 0.95 Then 'Checks to see if player 1 has less than a dollar, trying to determine if the user needs to spin again
MsgBox "Would you like to spin again? If so, press the Spin it Again button. If not, press the Next Player button" 'Tells user what to do next
cmdSpin1A.Visible = False 'Takes away first spin option
cmdSpin2A.Visible = True 'Gives user a choice to spin again
cmdNext.Visible = True 'Gives user the choice to pass their second spin
End If
If dblValue1 = 1 Then
MsgBox strNameP1 & " WINS!" 'Checks to see if player 1 has 1 dollar on first spin, if so he or she wins automatically
End
End If
End Sub
Private Sub cmdSpin2A_Click()
dblX = Int(Rnd * 20) 'Allows dblx to increment
dblValue2 = 0.05 * dblX + 0.05 'Makes the increment 0.05 to match the wheel on the show
MsgBox "You have a value of " & (dblValue2 * 100) & " cents for your second spin." 'Message box telling player 1 his or her second spin value
lblValue2.Caption = "Value of second spin: " & (dblValue2 * 100) 'Displays the value of the second spin for player 1
lblValue2.Visible = True 'Makes the second spin value for player one visible
dblTotal1 = (dblValue1 + dblValue2) 'Calculates the total for both spins, sum of dblValue1 plus dblValue2
lblValue3.Caption = "Total value of both spins: " & (dblTotal1 * 100) & " cents." 'Displays the total value of both spins
lblValue3.Visible = True 'Makes the total value label visible
If dblTotal1 > 1 Then 'Checks to see if player 1 went over 1 dollar, in which case player 2 wins automatically
MsgBox "You went over a dollar " & strNameP1 & ", you lose; " & strNameP2 & " wins." 'Informs player 1 that they have lost
End 'Ends the game in the event player 2 wins due to player 1 going over 1 dollar total value
End If
If dblTotal1 = 1 Then
MsgBox strNameP1 & " WINS!" 'Checks to see if player 1 has 1 dollar on first spin, if so he or she wins automatically
End
End If
MsgBox "Please press the Next Player button." 'Tells player 1 to press the next button
cmdSpin2A.Visible = False 'Removes Spin it Again option
End Sub
Private Sub cmdNext_Click()
lblValue1.Visible = False 'Removes player 1's first spin value
lblValue2.Visible = False 'Removes player 1's second spin value
lblValue3.Visible = False 'Removes player 1's total spin value for both spins
lblTurn.Caption = "It's " & strNameP2 & " turn." 'Changes the label that displays who's turn it is
cmdNext.Visible = False 'Removes option for player 2 to press Next Player
MsgBox "Spin the wheel by pressing the spin button, " & strNameP2 & "." 'Tells user what to do next
cmdSpin1B.Visible = True 'Makes the option for player 2 to spin for the first time
End Sub
Private Sub cmdSpin1B_Click()
dblValue4 = 0 'Sets intValue4 for spin 2 to 0 in case player 2 only spins once
dblX = Int(Rnd * 20) 'Allows dblx to increment
dblValue3 = 0.05 * dblX + 0.05 'Makes the increment 0.05 to match the wheel on the show
MsgBox "You have a value of " & (dblValue3 * 100) & " cents for your first spin." 'Message box telling player 2 his or her first spin value
lblValue1.Caption = "Value of first spin: " & (dblValue3 * 100) 'Displays the value of the first spin for player 2
lblValue1.Visible = True 'Makes label for player 2's first spin value visible
dblTotal2 = (dblValue3 + dblValue4) 'Calculates the total for both spins; for only one spin, the total is dblValue3
lblValue3.Caption = "Total value of both spins: " & (dblTotal2 * 100) & " cents." 'Displays the total value of both spins
lblValue3.Visible = True
If dblValue1 <= 0.95 Then 'Checks to see if player 2 has less than a dollar, trying to determine if the user needs to spin again
MsgBox "Would you like to spin again " & strNameP2 & "? If so, press the Spin it Again button. If not, press the Who Won button to see who won." 'Tells user what to do next
cmdSpin1B.Visible = False 'Hides first spin option for player 2
cmdSpin2B.Visible = True 'Makes the second spin option for player 2 visible
cmdWon.Visible = True 'Gives user the choice to use the value for their first spin as their total value and see who won
End If
If dblTotal2 = 1 Then
MsgBox strNameP2 & " WINS!" 'Checks to see if player 2 has 1 dollar on first spin, if so he or she wins automatically
End
End If
End Sub
Private Sub cmdSpin2B_Click()
dblX = Int(Rnd * 20) 'Allows dblx to increment
dblValue3 = 0.05 * dblX + 0.05 'Makes the increment 0.05 to match the wheel on the show
MsgBox "You have a value of " & (dblValue4 * 100) & " cents for your second spin." 'Message box telling player 2 his or her second spin value
lblValue2.Caption = "Value of second spin: " & (dblValue4 * 100) 'Displays the value of the second spin for player two
lblValue2.Visible = True 'Makes the label for the second spin value visible
dblTotal2 = (dblValue3 + dblValue4) 'Calculates the total for both spins, sum of intValue3 plus intValue4
lblValue3.Caption = "Total value of both spins: " & (dblTotal2 * 100) & " cents." 'Displays total value of both spins for player 2
lblValue3.Visible = True 'Makes the total value label for both spins visible
cmdSpin2B.Visible = False 'Removes option for player 2 to spin again
If dblTotal2 > 1 Then 'Checks to see if player 2 went over 1 dollar, in which case player 1 wins automatically
MsgBox "You went over a dollar " & strNameP2 & ", you lose; " & strNameP1 & " wins." 'Informs player 2 that they have lost
End 'Ends the game in the event player 1 wins due to player 2 going over 1 dollar total value
End If
If dblTotal2 = 1 Then
MsgBox strNameP2 & " WINS!" 'Checks to see if player 1 has 1 dollar on first spin, if so he or she wins automatically
End
End If
MsgBox "Please press the Who Won button to see who won." 'Tells user to press the Who Won button to see who won
cmdSpin2B.Visible = False 'Removes the spin again button for player 2
End Sub
Private Sub cmdWon_Click()
cmdSpin2A.Visible = False 'Removes the spin again button for player 1
lblValue1.Visible = False 'Removes the label showing the first spin value for player 2
lblValue2.Visible = False 'Removes the label showing the second spin value for player 2
lblValue3.Visible = False 'Removes the label showing the total spin value for player 2
If dblTotal1 <= 1 And dblTotal1 > dblTotal2 Then 'Decides if player 1 won by seeing if their total spun value is the closest to 100
lblWinner.Visible = True 'Displays winner label
MsgBox strNameP1 & " WINS!" 'Says player 1 wins
lblWinner.Caption = strNameP1 & " wins with a total of " & (dblTotal1 * 100) & " cents!" 'Says who won on the winner label and their total spun value
Else
lblWinner.Visible = True 'Says if player 1's total spun value wasn't closest to 100 the player 2's total spun value was
MsgBox strNameP2 & " WINS!" 'Says player 2 wins
lblWinner.Caption = strNameP2 & " wins with a total of " & (dblTotal2 * 100) & " cents!" 'Says who won on the winner label and their total spun value
End If
cmdWon.Visible = False
End Sub
Private Sub cmdDone_Click()
Unload Me 'Ends Game
End Sub