26. Create an application in VB to display 4 X 4 squares on the screen. One of the block will be active with black color all other block will be fill with blue color. Provide a command button as follows to move the active cell the active cell should be change only if it is within the boundary.


Dim Cnt As Integer
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
If (Cnt + 1) Mod 4 Then
Display(Cnt).BackColor = vbBlue
Cnt = Cnt + 1
Display(Cnt).BackColor = vbBlack
Else
Beep
End If
Case 1
If Cnt Mod 4 Then
Display(Cnt).BackColor = vbBlue
Cnt = Cnt – 1
Display(Cnt).BackColor = vbBlack
Else
Beep
End If
Case 2
If Cnt > 3 Then
Display(Cnt).BackColor = vbBlue
Cnt = Cnt – 4
Display(Cnt).BackColor = vbBlack
Else
Beep
End If
Case 3
If Cnt < 12 Then
Display(Cnt).BackColor = vbBlue
Cnt = Cnt + 4
Display(Cnt).BackColor = vbBlack
Else
Beep
End If

End Select
End Sub

Private Sub Form_Load()
Cnt = 0
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s