COLOUR DICE IN VB

To create Dice applicatio ,first of all, you draw a rounded square shape on a form

Secondly, you need to draw an array of 7 dots and VB will automatically labeled them as shape2(0), shape2(1),shape2(2), shape2(3), shape2(4), shape2(5) and shape2(6). You can control the appearance of the dots using the random function RND.

Program:-
Private Sub Command1_Click()
Dim n As Integer
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
Shape1.FillColor = &HC0C0C0
End If
If n = 2 Then
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape1.FillColor = &H8080FF
End If
If n = 3 Then
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
Shape1.FillColor = &H80FF&
End If
If n = 4 Then
Shape2(0).Visible = True
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape2(6).Visible = True
Shape1.FillColor = &HFFFF00
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
Shape1.FillColor = &HFFFF&
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
Shape1.FillColor = &HFF00FF
End If
End Sub

OUTPUT:-





Tic-Tac-Toe Game in VB

PROCEDURE:-
1. Create a new project in VB 6.0, Draw four lines on the form as shown in the figure.
2. Place an Image control on the form,  copy it and paste for 8 times (Image Control Array).
3. Now again place Image2, Image3 on the form and add Cross picture and Circle picture for player-1 and player-2 respectively.
4. Place two labels and change the caption as Player-1 and Player-2.
5.Place two command buttons and change their caption property as Play Again and Exit respectively.

Design View:-


PROGRAM CODE:-
Dim cross(8) As Boolean
Dim ball(8) As Boolean
Dim m As Integer
Dim player As Integer

Sub check_status()
If ball(0) = True And ball(1) = True And ball(2) = True Then
MsgBox "Player-1 Wins"
End If
If ball(3) = True And ball(4) = True And ball(5) = True Then
MsgBox "Player-1 Wins"
End If
If ball(6) = True And ball(7) = True And ball(8) = True Then
MsgBox "Player-1 Wins"
End If
If ball(0) = True And ball(3) = True And ball(6) = True Then
MsgBox "Player-1 Wins"
End If

If ball(1) = True And ball(4) = True And ball(7) = True Then
MsgBox "Player-1 Wins"
End If
If ball(2) = True And ball(5) = True And ball(8) = True Then
MsgBox "Player-1 Wins"
End If
If ball(0) = True And ball(4) = True And ball(8) = True Then
MsgBox "Player-1 Wins"
End If
If ball(2) = True And ball(4) = True And ball(6) = True Then
MsgBox "Player 1 Wins"
End If

If cross(0) = True And cross(1) = True And cross(2) = True Then
MsgBox "Player-2 Wins"
End If
If cross(3) = True And cross(4) = True And cross(5) = True Then
MsgBox "Player-2 Wins"
End If
If cross(6) = True And cross(7) = True And cross(8) = True Then
MsgBox "Player-2 Wins"
End If
If cross(0) = True And cross(3) = True And cross(6) = True Then
MsgBox "Player-2 Wins"
End If

If cross(1) = True And cross(4) = True And cross(7) = True Then
MsgBox "Player-2 Wins"
End If
If cross(2) = True And cross(5) = True And cross(8) = True Then
MsgBox "Player-2 Wins"
End If
If cross(0) = True And cross(4) = True And cross(8) = True Then
MsgBox "Player-2 Wins"
End If
If cross(2) = True And cross(4) = True And cross(6) = True Then
MsgBox "Player 2 wins"
End If
End Sub

Sub check_position()
For m = 0 To 8
If Image1(m).Picture = Image2.Picture Then
ball(m) = True
Else: ball(m) = False
End If
If Image1(m).Picture = Image3.Picture Then
cross(m) = True
Else
cross(m) = False
End If
Next
End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Command2_Click()
For m = 0 To 8
Image1(m).Picture = LoadPicture("")
Next
End Sub

Private Sub Image1_Click(Index As Integer)
check_position
If player = 1 And cross(Index) = False And ball(Index) = False Then
Image1(Index).Picture = Image2.Picture
End If
If player = 2 And cross(Index) = False And ball(Index) = False Then
Image1(Index).Picture = Image3.Picture
End If
check_position
check_status
End Sub

Private Sub Image2_Click()
player = 1
End Sub

Private Sub Image3_Click()
player = 2
End Sub

Private Sub mnuNew_Click()
For m = 0 To 8
Image1(m).Picture = LoadPicture("")
Next
End Sub

OUTPUT:-



Moving Image in VB



Property Table:-
OBJECT
PROPERTY
VALUE
Image1
Picture
Bitmap
Command1
Caption
Move Down
Command2
Caption
Move Up
Command3
Caption
Move Left
Command4
Caption
Move Right
 
 CODE:-
Dim x As Integer
Dim y As Integer
Dim v, w As Integer
Private Sub Command1_Click()
w = w + 10
If w < 3670 Then
Image1.Move v, w
Else
Image1.Move 2640, 1560
v = 2640
w = 1560

End If
End Sub

Private Sub Command2_Click()
w = w - 10
If w > 0 Then
Image1.Move v, w
Else
Image1.Move 2640, 1560
v = 2640
w = 1560
End If
End Sub

Private Sub Command3_Click()
v = v + 10
If v < 5350 Then
Image1.Move v, w
Else
Image1.Move 2640, 1560
v = 2640
w = 1560
End If
End Sub

Private Sub Command4_Click()
v = v - 10
If v > 0 Then
Image1.Move v, w
Else
Image1.Move 2640, 1560
v = 2640
w = 1560
End If
End Sub


COLOUR DICE IN VB

To create Dice applicatio ,first of all, you draw a rounded square shape on a form

Secondly, you need to draw an array of 7 dots and VB will automatically labeled them as shape2(0), shape2(1),shape2(2), shape2(3), shape2(4), shape2(5) and shape2(6). You can control the appearance of the dots using the random function RND.

Program:-
Private Sub Command1_Click()
Dim n As Integer
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
Shape1.FillColor = &HC0C0C0
End If
If n = 2 Then
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape1.FillColor = &H8080FF
End If
If n = 3 Then
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
Shape1.FillColor = &H80FF&
End If
If n = 4 Then
Shape2(0).Visible = True
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape2(6).Visible = True
Shape1.FillColor = &HFFFF00
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
Shape1.FillColor = &HFFFF&
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
Shape1.FillColor = &HFF00FF
End If
End Sub

OUTPUT:-





Tic-Tac-Toe Game in VB

PROCEDURE:-
1. Create a new project in VB 6.0, Draw four lines on the form as shown in the figure.
2. Place an Image control on the form,  copy it and paste for 8 times (Image Control Array).
3. Now again place Image2, Image3 on the form and add Cross picture and Circle picture for player-1 and player-2 respectively.
4. Place two labels and change the caption as Player-1 and Player-2.
5.Place two command buttons and change their caption property as Play Again and Exit respectively.

Design View:-


PROGRAM CODE:-
Dim cross(8) As Boolean
Dim ball(8) As Boolean
Dim m As Integer
Dim player As Integer

Sub check_status()
If ball(0) = True And ball(1) = True And ball(2) = True Then
MsgBox "Player-1 Wins"
End If
If ball(3) = True And ball(4) = True And ball(5) = True Then
MsgBox "Player-1 Wins"
End If
If ball(6) = True And ball(7) = True And ball(8) = True Then
MsgBox "Player-1 Wins"
End If
If ball(0) = True And ball(3) = True And ball(6) = True Then
MsgBox "Player-1 Wins"
End If

If ball(1) = True And ball(4) = True And ball(7) = True Then
MsgBox "Player-1 Wins"
End If
If ball(2) = True And ball(5) = True And ball(8) = True Then
MsgBox "Player-1 Wins"
End If
If ball(0) = True And ball(4) = True And ball(8) = True Then
MsgBox "Player-1 Wins"
End If
If ball(2) = True And ball(4) = True And ball(6) = True Then
MsgBox "Player 1 Wins"
End If

If cross(0) = True And cross(1) = True And cross(2) = True Then
MsgBox "Player-2 Wins"
End If
If cross(3) = True And cross(4) = True And cross(5) = True Then
MsgBox "Player-2 Wins"
End If
If cross(6) = True And cross(7) = True And cross(8) = True Then
MsgBox "Player-2 Wins"
End If
If cross(0) = True And cross(3) = True And cross(6) = True Then
MsgBox "Player-2 Wins"
End If

If cross(1) = True And cross(4) = True And cross(7) = True Then
MsgBox "Player-2 Wins"
End If
If cross(2) = True And cross(5) = True And cross(8) = True Then
MsgBox "Player-2 Wins"
End If
If cross(0) = True And cross(4) = True And cross(8) = True Then
MsgBox "Player-2 Wins"
End If
If cross(2) = True And cross(4) = True And cross(6) = True Then
MsgBox "Player 2 wins"
End If
End Sub

Sub check_position()
For m = 0 To 8
If Image1(m).Picture = Image2.Picture Then
ball(m) = True
Else: ball(m) = False
End If
If Image1(m).Picture = Image3.Picture Then
cross(m) = True
Else
cross(m) = False
End If
Next
End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Command2_Click()
For m = 0 To 8
Image1(m).Picture = LoadPicture("")
Next
End Sub

Private Sub Image1_Click(Index As Integer)
check_position
If player = 1 And cross(Index) = False And ball(Index) = False Then
Image1(Index).Picture = Image2.Picture
End If
If player = 2 And cross(Index) = False And ball(Index) = False Then
Image1(Index).Picture = Image3.Picture
End If
check_position
check_status
End Sub

Private Sub Image2_Click()
player = 1
End Sub

Private Sub Image3_Click()
player = 2
End Sub

Private Sub mnuNew_Click()
For m = 0 To 8
Image1(m).Picture = LoadPicture("")
Next
End Sub

OUTPUT:-



Moving Image in VB



Property Table:-
OBJECT
PROPERTY
VALUE
Image1
Picture
Bitmap
Command1
Caption
Move Down
Command2
Caption
Move Up
Command3
Caption
Move Left
Command4
Caption
Move Right
 
 CODE:-
Dim x As Integer
Dim y As Integer
Dim v, w As Integer
Private Sub Command1_Click()
w = w + 10
If w < 3670 Then
Image1.Move v, w
Else
Image1.Move 2640, 1560
v = 2640
w = 1560

End If
End Sub

Private Sub Command2_Click()
w = w - 10
If w > 0 Then
Image1.Move v, w
Else
Image1.Move 2640, 1560
v = 2640
w = 1560
End If
End Sub

Private Sub Command3_Click()
v = v + 10
If v < 5350 Then
Image1.Move v, w
Else
Image1.Move 2640, 1560
v = 2640
w = 1560
End If
End Sub

Private Sub Command4_Click()
v = v - 10
If v > 0 Then
Image1.Move v, w
Else
Image1.Move 2640, 1560
v = 2640
w = 1560
End If
End Sub