Option Explicit
Private lngTotal As Long
Private lngPoints As Long
Private intRandom As Integer
Private strButton As String
Private Sub cmdDone_Click()
Unload Me
End Sub
Private Sub cmdHigh_Click()
lngPoints = txtRisk.Text
If lngTotal = 0 Then
MsgBox ("Game Over!!!")
ElseIf lngPoints > lngTotal Then
MsgBox ("You dont have that many points to risk!")
Else
strButton = "High"
lngTotal = RndInt(lngTotal, strButton, intRandom, lngPoints)
txtRisk.Text = ""
lblPoints.Caption = "Total Points = " & lngTotal
End If
End Sub
Function RndInt(ByVal lngTotal As Long, ByVal strButton As String, ByRef intRandom As Integer, ByRef lngPoints As Long) As Long
intRandom = Int(13 * Rnd + 1)
If strButton = "High" Then
If intRandom > 7 Then
RndInt = lngTotal + (lngPoints * 2)
lblMessage.Caption = "You win. The number was" & Space(1) & intRandom
ElseIf intRandom < 8 Then
RndInt = lngTotal - lngPoints
lblMessage.Caption = "You lose. The number was" & Space(1) & intRandom
End If
Else
If intRandom > 7 Then
RndInt = lngTotal - lngPoints
lblMessage.Caption = "You lose. The number was" & Space(1) & intRandom
ElseIf intRandom < 8 Then
RndInt = lngTotal + (lngPoints * 2)
lblMessage.Caption = "You win. The number was" & Space(1) & intRandom
End If
End If
End Function
Private Sub cmdLow_Click()
lngPoints = txtRisk.Text
If lngTotal = 0 Then
MsgBox ("Game Over!")
ElseIf lngPoints > lngTotal Then
MsgBox ("You dont have that many points to risk!")
Else
strButton = "Low"
lngTotal = RndInt(lngTotal, strButton, intRandom, lngPoints)
txtRisk.Text = ""
lblPoints.Caption = "Total Points = " & lngTotal
End If
End Sub
Private Sub Form_Load()
Randomize
intRandom = Int(13 * Rnd + 1)
lngTotal = 1000
lblPoints.Caption = "Total Points = " & lngTotal
End Sub