Casino Slot Machine

 

  This is a much improved version of VB slot machine. Instead of drawing nine shapes, now I draw only three shapes and change their shapes randomly using the shapes' properties at runtime. I use the function shape1(0).shape=n to change the shapes, where n is a random number taking the values 3, 4 and 5, which  correspond to a circle, a rectangle and a square. I also added the amount to bet and the credits that are won. Besides, I added an item on the menu bar, help, using menu editor.

The Interface

 

 

 

 

 

 

The Codes

Private Sub Command1_Click()
Label2.Caption = "Your Credits"
amount = Val(Text1)
Randomize Timer
a = 3 + Int(Rnd * 3)
b = 3 + Int(Rnd * 3)
c = 3 + Int(Rnd * 3)

Label1.Caption = " "

Shape1(0).Shape = a
If a = 3 Then
Shape1(0).FillColor = &HFF00&
End If
If a = 4 Then
Shape1(0).FillColor = &HFF00FF
End If


If a = 5 Then
Shape1(0).FillColor = &HFF0000
End If


Shape1(1).Shape = b
If b = 3 Then
Shape1(1).FillColor = &HFF00&
End If
If b = 4 Then
Shape1(1).FillColor = &HFF00FF
End If

If b = 5 Then
Shape1(1).FillColor = &HFF0000
End If

Shape1(2).Shape = c
If c = 3 Then
Shape1(2).FillColor = &HFF00&
End If


If c = 4 Then
Shape1(2).FillColor = &HFF00FF
End If
If c = 5 Then
Shape1(2).FillColor = &HFF0000
End If

 

 



If (a = 3 And b = 3 And c <> 3) Or (a = 3 And c = 3 And b <> 3) Or (b = 3 And c = 3 And a <> 3) Then
Label1.Caption = " You win 10 dollars"
amount = amount + 10
End If

If (a = 4 And b = 4 And c <> 4) Or (a = 4 And c = 4 And b <> 4) Or (b = 4 And c = 4 And a <> 4) Then
Label1.Caption = " You win 20 dollars"
amount = amount + 20
End If

If (a = 5 And b = 5 And c <> 5) Or (a = 5 And c = 5 And b <> 5) Or (b = 5 And c = 5 And a <> 5) Then
Label1.Caption = " You win 30 dollars"
amount = amount + 30
End If

If (a = 3 And b = 3 And c = 3) Or (a = 4 And b = 4 And c = 4) Or (a = 5 And b = 5 And c = 5) Then
Label1.Caption = " Congratulation! Jackpot!!! You win 200 dollars!"
amount = amount + 200
End If

If (a = 3 And b = 4 And c = 5) Or (a = 3 And b = 5 And c = 4) Or (a = 4 And b = 3 And c = 5) Or (a = 4 And b = 5 And c = 3) Or (a = 5 And b = 4 And c = 3) Or (a = 5 And b = 3 And c = 4) Then

Label1.Caption = " Too bad, you lost 50 dollars"
amount = amount - 50
End If

If amount < 0 Then
Label1.Caption = "Oh! you're bankrupt!"
End If
amount = amount - 20
Text1.Text = Str$(amount)
End Sub




Private Sub Form_Click()
Label3.Visible = False
End Sub

Private Sub Form_Load()
Label1.Caption = " Welcome to Play"
Label3.Visible = False

End Sub

Private Sub instruct_click()
Label3.Visible = True
End Sub

Private Sub Text1_Change()
amount = Val(Text1)
End Sub

 

 

 

 

[Back to VB Sample Programs]