Find The Number.. VB Program Code

 Place TextBox, Label, Timer and a CommandButton on a form. Set the Timer1 Interval property to 100, Change the caption of Label1 as (blank) " " and change the Command1 caption property as Get password. Following vb code is used to finding the password. Ex: password is 103

   Dim password As Integer
    Dim crackpass As Integer

    Private Sub Command1_Click()
    Timer1.Enabled = True
    End Sub

    Private Sub Form_Load()
    password = 103
    End Sub

    Private Sub Timer1_Timer()
    Randomize Timer
    crackpass = Int(Rnd * 100) + 100
    If crackpass = password Then
    Timer1.Enabled = False
    Text1.Text = crackpass
    Label1.Visible = True
    Label1.Caption = "Password Cracked!Login Successful!"
    Else
    Text1.Text = crackpass
    Label1.Visible = True
    Label1.Caption = "Please wait..."
    End If
    End Sub


Star War Game VB Program Code


This game is used for educational purpose. This program demonstrates the principle of projectile in physics. At a certain angle and a certain launch velocity, the projectile can reach a certain range and certain height. The maximum range is at an angle of 45 degree. This principle can be applied in the military field where a missile can be launched at a certain velocity and certain angle to hit a remote target. It can also be applied in other scientific and technological fields. This game provides a good training for students in their abilities in making estimation.
In this program, we use the formulae v sin A - (1/2)gt2  as  the vertical component of the displacement and v cos A as the horizontal component  of the displacement( where g is the gravitational acceleration , v the launch velocity and A the launch angle). To enable the missile to fly, we used a combination of the Object.Move method  and the object coordinate system , i.e. object. left and object.Top.
We also use the randomize method so that the objects will appear at different positions randomly at each new game. In addition, we use the randomize method to load different backgrounds at start up and at each new game.

Dim x As Variant
Dim a As Variant
Dim t As Variant
Dim y As Variant
Dim w As Variant
Dim i As Variant
Dim score As Integer
Dim left1, left2, left3, top1, top2, top3 As Variant
Dim backgr As Integer
Sub showfire()
Timer2.Enabled = True
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
w = 0
Image1.Visible = True
Timer1.Enabled = False
Label4(0).Visible = False
Label4(1).Visible = False
Label4(2).Visible = False
Label3.Caption = ""
Image1.Move 360, 6360
t = 0
End Sub
Private Sub Form_Click()
Label5.Visible = False
End Sub
Private Sub Form_Load()
Randomize Timer
left1 = Int(Rnd * 7000) + 1000
left2 = Int(Rnd * 7000) + 1000
left3 = Int(Rnd * 7000) + 1000
top1 = Int(Rnd * 5000) + 100
top2 = Int(Rnd * 5000) + 100
top3 = Int(Rnd * 5000) + 100
'To set the initial positions of the objects
Image2.Left = left1
Image3.Left = left2
Image4.Left = left3
Image2.Top = top1
Image3.Top = top2
Image4.Top = top3
w = 0
score = 0
Label7.Caption = Str$(score)
End Sub
Private Sub Image7_Click()
Label5.Visible = False
End Sub
Private Sub Instruct_Click()
Label5.Visible = True
Label5.Caption = "To play the game, you need to key in the velocity and the angle. The range of angle should be between 0 and 90 degree. After entering the above values, click launch to play. After every trial, you have to reset the game. After striking all the objects, press File menu and select new game to play again."
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub mnunew_Click()
w = 0
Randomize Timer
'To display all the objects again
left1 = Int(Rnd * 7000) + 1000
left2 = Int(Rnd * 7000) + 1000
left3 = Int(Rnd * 7000) + 1000
top1 = Int(Rnd * 5000) + 100
top2 = Int(Rnd * 5000) + 100
top3 = Int(Rnd * 5000) + 100
Image2.Left = left1
Image3.Left = left2
Image4.Left = left3
Image2.Top = top1
Image3.Top = top2
Image4.Top = top3
Image2.Visible = True
Image3.Visible = True
Image4.Visible = True
Image1.Visible = True
Timer1.Enabled = False
Label4(0).Visible = False
Label4(1).Visible = False
Label4(0).Visible = False
Label3.Caption = ""
Image1.Move 360, 6360
t = 0
End Sub
'To simulate rocket flight using projectile equation
Private Sub Timer1_Timer()
MMControl1.Command = "close"
If Image1.Left < 15000 And Image1.Top < 9000 Then
v = Val(Text1.Text)
a = Val(Text2.Text)
t = t + 1
y = v * Sin(a * 3.141592654 / 180) * t - 4.9 * (t ^ 2)
x = v * Cos(a * 3.141592654 / 180) * t
Image1.Move Image1.Left + x, Image1.Top - y
If Image4.Visible = True And (Image1.Left < left3 + 240 And Image1.Left > left3 - 240) And (Image1.Top < top3 + 240 And Image1.Top > top3 - 240) Then
i = 2
Timer1.Enabled = False
showfire
Image4.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the satellite!"
Label4(2).Left = left3 + 240
Label4(2).Top = top3 + 240
Label4(2).Visible = True
Image5(2).Left = left3 + 240
Image5(2).Top = top3 + 240
score = score + 50
ElseIf Image3.Visible = True And (Image1.Left < left2 + 240 And Image1.Left > left2 - 240) And (Image1.Top < top2 + 240 And Image1.Top > top2 - 240) Then
Timer1.Enabled = False
i = 1
showfire
Image3.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the rocket!"
Label4(1).Left = left2 + 240
Label4(1).Top = top2 + 240
Label4(1).Visible = True
Image5(1).Left = left2 + 240
Image5(1).Top = top2 + 240
score = score + 100
ElseIf Image2.Visible = True And (Image1.Left < left1 + 240 And Image1.Left > left1 - 240) And (Image1.Top < top1 + 240 And Image1.Top > top1 - 240) Then
Timer1.Enabled = False
i = 0
showfire
Image2.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the Saturn!"
Label4(0).Left = left1 + 240
Label4(0).Top = top1 + 240
Label4(0).Visible = True
Image5(0).Left = left1 + 240
Image5(0).Top = top1 + 240
score = score + 200
End If
Else
Label3.Caption = "You miss the target!"
Timer1.Enabled = False
End If
Label7.Caption = Str$(score)
End Sub
Private Sub Timer2_Timer()
w = w + 1
If w < 30 Then
Image5(i).Visible = True
Label4(i).Visible = True
Else
Image5(i).Visible = False
Label4(i).Visible = False
Timer2.Enabled = False
End If
End Sub



LUCKY DRAW PROGRAM IN VB

This is a simple VB program consists of  a 3x3 matrix, which means there are 9 command buttons in a grid. The command buttons are created as controls in an array, and they are differentiated by their indices. One of the button contains a prize,  when you click on it, it  displays the word "prize" on the caption. If you do not  strike the prize , the word "The Prize is here! " will appear on the command button that contains the prize.
Random integers from 1 to 9 can be created using the statement n=Int(Rnd*9) where Int is a function that converts numbers to integers and Rnd is a method hat generates random numbers between 0 and 1. When the user click a command button, a random number between 0 and 9 is generated and if this number corresponds to the index of the command button, it will show the word "Prize" on the clicked command button  , otherwise, it shows the words "The Prize is here!" on the command button with an index corresponds to the generated number.

PROGRAM: -

Private Sub Command1_Click(Index As Integer)
Dim n As Integer
For n = 0 To 8
Command1(n).Caption = ""
Next
Randomize Timer
n = Int(Rnd * 9)
If Index = n Then
Command1(n).Caption = "Prize"
Else: Command1(n).Caption = "The Prize is here!"
End If
End Sub

OUTPUT:-

 

SLOT MACHINE IN VB

Use a timer and a subprogram to create the animation effect. Besides, you have to add the Multimedia Control to produce the sound effects. To include the multimedia control as one of the tools, click on project on the menu and select components, then click on Microsoft Multimedia Control 6.0. Drag the Multimedia Control into your form and make it invisible at startup. In this program, we use two Multimedia controls, one for playing the spinning sound and the other for the jackpot sound. Below is the interface and the code.

PROPERTY TABLE:

OBJECT
PROPERTY
VALUE
Label1
Caption
GOOD LUCK
Label2
Caption
YOUR CREDITS
Shape1
Shape
Rounded Rectangle
Shape2(0)
Shape
Rectangle
Shape2(1)
Shape
Rectangle
Shape2(2)
Shape
Rectangle
Text1
Text
Blank
Command1
Caption
Press to Spin
Command2
Caption
Stop
Timer1                               -             Interval-                                        1000

PROGRAM:

Dim amount, x, a, b, c  As Integer

Private Sub Command1_Click()
Timer1.Enabled = True
MMControl1.Command = "Close"
MMControl2.Command = "close"

x = 0
Label2.Caption = "Your Credits"
amount = Val(Text1)
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

Private Sub Timer1_Timer()
If x < 500 Then
spin
Else
Timer1.Enabled = False
MMControl1.Command = "Stop"
Label1.Alignment = 2


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 20 dollars"
amount = amount + 20
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 30 dollars"
amount = amount + 30
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 40 dollars"
amount = amount + 40
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
MMControl2.Notify = False
MMControl2.Wait = True
MMControl2.Shareable = False
MMControl2.DeviceType = "WaveAudio"
MMControl2.FileName = "D:\Liew Folder\VB program\audio\endgame.wav"
MMControl2.Command = "Open"
MMControl2.Command = "Play"

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
Text1.Text = Str$(amount)
End If
End Sub

Sub spin()

x = x + 10
Randomize Timer
a = 3 + Int(Rnd * 3)
b = 3 + Int(Rnd * 3)
c = 3 + Int(Rnd * 3)

MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\slot2.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"

Label1.Caption = "Good Luck!"
Label1.Alignment = a - 3
Shape2(0).Shape = a
If a = 3 Then
Shape2(0).FillColor = &HFF00&
End If
If a = 4 Then
Shape2(0).FillColor = &HFF00FF
End If
If a = 5 Then
Shape2(0).FillColor = &HFF0000
End If
Shape2(1).Shape = b
If b = 3 Then
Shape2(1).FillColor = &HFF00&
End If
If b = 4 Then
Shape2(1).FillColor = &HFF00FF
End If
If b = 5 Then
Shape2(1).FillColor = &HFF0000
End If
Shape2(2).Shape = c
If c = 3 Then
Shape2(2).FillColor = &HFF00&
End If
If c = 4 Then
Shape2(2).FillColor = &HFF00FF
End If
If c = 5 Then
Shape2(2).FillColor = &HFF0000
End If
End Sub

OUTPUT:


DICE VB PROGRAM


To create Dice applicatio ,first of all, you draw a rounded square in the project windows. 
Secondly, you need to draw an array of 7 dots and VB will automatically labeled them as 
shape1(0), shape1(1),shape1(2), shape1(3), shape1(4), shape1(5) and shape1(6). You can
control the appearance of the dots using the random function RND.


Private Sub Command1_Click()
Randomize Timer
n = Int(1 + Rnd * 6)
For i = 0 To 6
Shape2(i).Visible = False
Next


If n = 1 Then
Shape2(3).Visible = True

End If


If n = 2 Then
Shape2(2).Visible = True
Shape2(4).Visible = True
End If

If n = 3 Then
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
End If

If n = 4 Then
Shape2(0).Visible = True
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape2(6).Visible = True
End If


If n = 5 Then
Shape2(0).Visible = True
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
Shape2(6).Visible = True

End If
If n = 6 Then
Shape2(0).Visible = True
Shape2(1).Visible = True
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape2(5).Visible = True
Shape2(6).Visible = True

End If
End Sub




OUTPUT:

Find The Number.. VB Program Code

 Place TextBox, Label, Timer and a CommandButton on a form. Set the Timer1 Interval property to 100, Change the caption of Label1 as (blank) " " and change the Command1 caption property as Get password. Following vb code is used to finding the password. Ex: password is 103

   Dim password As Integer
    Dim crackpass As Integer

    Private Sub Command1_Click()
    Timer1.Enabled = True
    End Sub

    Private Sub Form_Load()
    password = 103
    End Sub

    Private Sub Timer1_Timer()
    Randomize Timer
    crackpass = Int(Rnd * 100) + 100
    If crackpass = password Then
    Timer1.Enabled = False
    Text1.Text = crackpass
    Label1.Visible = True
    Label1.Caption = "Password Cracked!Login Successful!"
    Else
    Text1.Text = crackpass
    Label1.Visible = True
    Label1.Caption = "Please wait..."
    End If
    End Sub


Star War Game VB Program Code


This game is used for educational purpose. This program demonstrates the principle of projectile in physics. At a certain angle and a certain launch velocity, the projectile can reach a certain range and certain height. The maximum range is at an angle of 45 degree. This principle can be applied in the military field where a missile can be launched at a certain velocity and certain angle to hit a remote target. It can also be applied in other scientific and technological fields. This game provides a good training for students in their abilities in making estimation.
In this program, we use the formulae v sin A - (1/2)gt2  as  the vertical component of the displacement and v cos A as the horizontal component  of the displacement( where g is the gravitational acceleration , v the launch velocity and A the launch angle). To enable the missile to fly, we used a combination of the Object.Move method  and the object coordinate system , i.e. object. left and object.Top.
We also use the randomize method so that the objects will appear at different positions randomly at each new game. In addition, we use the randomize method to load different backgrounds at start up and at each new game.

Dim x As Variant
Dim a As Variant
Dim t As Variant
Dim y As Variant
Dim w As Variant
Dim i As Variant
Dim score As Integer
Dim left1, left2, left3, top1, top2, top3 As Variant
Dim backgr As Integer
Sub showfire()
Timer2.Enabled = True
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
w = 0
Image1.Visible = True
Timer1.Enabled = False
Label4(0).Visible = False
Label4(1).Visible = False
Label4(2).Visible = False
Label3.Caption = ""
Image1.Move 360, 6360
t = 0
End Sub
Private Sub Form_Click()
Label5.Visible = False
End Sub
Private Sub Form_Load()
Randomize Timer
left1 = Int(Rnd * 7000) + 1000
left2 = Int(Rnd * 7000) + 1000
left3 = Int(Rnd * 7000) + 1000
top1 = Int(Rnd * 5000) + 100
top2 = Int(Rnd * 5000) + 100
top3 = Int(Rnd * 5000) + 100
'To set the initial positions of the objects
Image2.Left = left1
Image3.Left = left2
Image4.Left = left3
Image2.Top = top1
Image3.Top = top2
Image4.Top = top3
w = 0
score = 0
Label7.Caption = Str$(score)
End Sub
Private Sub Image7_Click()
Label5.Visible = False
End Sub
Private Sub Instruct_Click()
Label5.Visible = True
Label5.Caption = "To play the game, you need to key in the velocity and the angle. The range of angle should be between 0 and 90 degree. After entering the above values, click launch to play. After every trial, you have to reset the game. After striking all the objects, press File menu and select new game to play again."
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub mnunew_Click()
w = 0
Randomize Timer
'To display all the objects again
left1 = Int(Rnd * 7000) + 1000
left2 = Int(Rnd * 7000) + 1000
left3 = Int(Rnd * 7000) + 1000
top1 = Int(Rnd * 5000) + 100
top2 = Int(Rnd * 5000) + 100
top3 = Int(Rnd * 5000) + 100
Image2.Left = left1
Image3.Left = left2
Image4.Left = left3
Image2.Top = top1
Image3.Top = top2
Image4.Top = top3
Image2.Visible = True
Image3.Visible = True
Image4.Visible = True
Image1.Visible = True
Timer1.Enabled = False
Label4(0).Visible = False
Label4(1).Visible = False
Label4(0).Visible = False
Label3.Caption = ""
Image1.Move 360, 6360
t = 0
End Sub
'To simulate rocket flight using projectile equation
Private Sub Timer1_Timer()
MMControl1.Command = "close"
If Image1.Left < 15000 And Image1.Top < 9000 Then
v = Val(Text1.Text)
a = Val(Text2.Text)
t = t + 1
y = v * Sin(a * 3.141592654 / 180) * t - 4.9 * (t ^ 2)
x = v * Cos(a * 3.141592654 / 180) * t
Image1.Move Image1.Left + x, Image1.Top - y
If Image4.Visible = True And (Image1.Left < left3 + 240 And Image1.Left > left3 - 240) And (Image1.Top < top3 + 240 And Image1.Top > top3 - 240) Then
i = 2
Timer1.Enabled = False
showfire
Image4.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the satellite!"
Label4(2).Left = left3 + 240
Label4(2).Top = top3 + 240
Label4(2).Visible = True
Image5(2).Left = left3 + 240
Image5(2).Top = top3 + 240
score = score + 50
ElseIf Image3.Visible = True And (Image1.Left < left2 + 240 And Image1.Left > left2 - 240) And (Image1.Top < top2 + 240 And Image1.Top > top2 - 240) Then
Timer1.Enabled = False
i = 1
showfire
Image3.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the rocket!"
Label4(1).Left = left2 + 240
Label4(1).Top = top2 + 240
Label4(1).Visible = True
Image5(1).Left = left2 + 240
Image5(1).Top = top2 + 240
score = score + 100
ElseIf Image2.Visible = True And (Image1.Left < left1 + 240 And Image1.Left > left1 - 240) And (Image1.Top < top1 + 240 And Image1.Top > top1 - 240) Then
Timer1.Enabled = False
i = 0
showfire
Image2.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the Saturn!"
Label4(0).Left = left1 + 240
Label4(0).Top = top1 + 240
Label4(0).Visible = True
Image5(0).Left = left1 + 240
Image5(0).Top = top1 + 240
score = score + 200
End If
Else
Label3.Caption = "You miss the target!"
Timer1.Enabled = False
End If
Label7.Caption = Str$(score)
End Sub
Private Sub Timer2_Timer()
w = w + 1
If w < 30 Then
Image5(i).Visible = True
Label4(i).Visible = True
Else
Image5(i).Visible = False
Label4(i).Visible = False
Timer2.Enabled = False
End If
End Sub



LUCKY DRAW PROGRAM IN VB

This is a simple VB program consists of  a 3x3 matrix, which means there are 9 command buttons in a grid. The command buttons are created as controls in an array, and they are differentiated by their indices. One of the button contains a prize,  when you click on it, it  displays the word "prize" on the caption. If you do not  strike the prize , the word "The Prize is here! " will appear on the command button that contains the prize.
Random integers from 1 to 9 can be created using the statement n=Int(Rnd*9) where Int is a function that converts numbers to integers and Rnd is a method hat generates random numbers between 0 and 1. When the user click a command button, a random number between 0 and 9 is generated and if this number corresponds to the index of the command button, it will show the word "Prize" on the clicked command button  , otherwise, it shows the words "The Prize is here!" on the command button with an index corresponds to the generated number.

PROGRAM: -

Private Sub Command1_Click(Index As Integer)
Dim n As Integer
For n = 0 To 8
Command1(n).Caption = ""
Next
Randomize Timer
n = Int(Rnd * 9)
If Index = n Then
Command1(n).Caption = "Prize"
Else: Command1(n).Caption = "The Prize is here!"
End If
End Sub

OUTPUT:-

 

SLOT MACHINE IN VB

Use a timer and a subprogram to create the animation effect. Besides, you have to add the Multimedia Control to produce the sound effects. To include the multimedia control as one of the tools, click on project on the menu and select components, then click on Microsoft Multimedia Control 6.0. Drag the Multimedia Control into your form and make it invisible at startup. In this program, we use two Multimedia controls, one for playing the spinning sound and the other for the jackpot sound. Below is the interface and the code.

PROPERTY TABLE:

OBJECT
PROPERTY
VALUE
Label1
Caption
GOOD LUCK
Label2
Caption
YOUR CREDITS
Shape1
Shape
Rounded Rectangle
Shape2(0)
Shape
Rectangle
Shape2(1)
Shape
Rectangle
Shape2(2)
Shape
Rectangle
Text1
Text
Blank
Command1
Caption
Press to Spin
Command2
Caption
Stop
Timer1                               -             Interval-                                        1000

PROGRAM:

Dim amount, x, a, b, c  As Integer

Private Sub Command1_Click()
Timer1.Enabled = True
MMControl1.Command = "Close"
MMControl2.Command = "close"

x = 0
Label2.Caption = "Your Credits"
amount = Val(Text1)
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

Private Sub Timer1_Timer()
If x < 500 Then
spin
Else
Timer1.Enabled = False
MMControl1.Command = "Stop"
Label1.Alignment = 2


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 20 dollars"
amount = amount + 20
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 30 dollars"
amount = amount + 30
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 40 dollars"
amount = amount + 40
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
MMControl2.Notify = False
MMControl2.Wait = True
MMControl2.Shareable = False
MMControl2.DeviceType = "WaveAudio"
MMControl2.FileName = "D:\Liew Folder\VB program\audio\endgame.wav"
MMControl2.Command = "Open"
MMControl2.Command = "Play"

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
Text1.Text = Str$(amount)
End If
End Sub

Sub spin()

x = x + 10
Randomize Timer
a = 3 + Int(Rnd * 3)
b = 3 + Int(Rnd * 3)
c = 3 + Int(Rnd * 3)

MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\slot2.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"

Label1.Caption = "Good Luck!"
Label1.Alignment = a - 3
Shape2(0).Shape = a
If a = 3 Then
Shape2(0).FillColor = &HFF00&
End If
If a = 4 Then
Shape2(0).FillColor = &HFF00FF
End If
If a = 5 Then
Shape2(0).FillColor = &HFF0000
End If
Shape2(1).Shape = b
If b = 3 Then
Shape2(1).FillColor = &HFF00&
End If
If b = 4 Then
Shape2(1).FillColor = &HFF00FF
End If
If b = 5 Then
Shape2(1).FillColor = &HFF0000
End If
Shape2(2).Shape = c
If c = 3 Then
Shape2(2).FillColor = &HFF00&
End If
If c = 4 Then
Shape2(2).FillColor = &HFF00FF
End If
If c = 5 Then
Shape2(2).FillColor = &HFF0000
End If
End Sub

OUTPUT:


DICE VB PROGRAM


To create Dice applicatio ,first of all, you draw a rounded square in the project windows. 
Secondly, you need to draw an array of 7 dots and VB will automatically labeled them as 
shape1(0), shape1(1),shape1(2), shape1(3), shape1(4), shape1(5) and shape1(6). You can
control the appearance of the dots using the random function RND.


Private Sub Command1_Click()
Randomize Timer
n = Int(1 + Rnd * 6)
For i = 0 To 6
Shape2(i).Visible = False
Next


If n = 1 Then
Shape2(3).Visible = True

End If


If n = 2 Then
Shape2(2).Visible = True
Shape2(4).Visible = True
End If

If n = 3 Then
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
End If

If n = 4 Then
Shape2(0).Visible = True
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape2(6).Visible = True
End If


If n = 5 Then
Shape2(0).Visible = True
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
Shape2(6).Visible = True

End If
If n = 6 Then
Shape2(0).Visible = True
Shape2(1).Visible = True
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape2(5).Visible = True
Shape2(6).Visible = True

End If
End Sub




OUTPUT: