frmMain.frm

 VERSION 5.00
Begin VB.Form frmMain
   BackColor       =   &H80000003&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Catch and Match"
   ClientHeight    =   3360
   ClientLeft      =   45
   ClientTop       =   615
   ClientWidth     =   3360
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3360
   ScaleWidth      =   3360
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   16
      Left            =   2520
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   15
      Top             =   2520
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   15
      Left            =   1680
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   14
      Top             =   2520
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   14
      Left            =   840
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   13
      Top             =   2520
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   13
      Left            =   0
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   2520
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   12
      Left            =   2520
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   11
      Top             =   1680
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   11
      Left            =   1680
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   1680
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   10
      Left            =   840
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   1680
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   9
      Left            =   0
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   8
      Top             =   1680
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   8
      Left            =   2520
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   7
      Top             =   840
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   7
      Left            =   1680
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   840
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   6
      Left            =   840
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   840
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   5
      Left            =   0
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   840
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   4
      Left            =   2520
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   0
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   3
      Left            =   1680
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   0
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   2
      Left            =   840
      MaskColor       =   &H00FF0000&
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   0
      Width           =   855
   End
   Begin VB.CommandButton cmdChar
      BackColor       =   &H00FFC0C0&
      BeginProperty Font
         Name            =   "Arial"
         Size            =   20.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Index           =   1
      Left            =   0
      MaskColor       =   &H8000000F&
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   0
      UseMaskColor    =   -1  'True
      Width           =   855
   End
   Begin VB.Menu mnuGame
      Caption         =   "&Game"
      Begin VB.Menu mnuNew
         Caption         =   "&New Game"
         Shortcut        =   {F2}
      End
      Begin VB.Menu mnuHigh
         Caption         =   "&High Score"
      End
      Begin VB.Menu mnuExit
         Caption         =   "Exit"
      End
   End
   Begin VB.Menu mnuHelp
      Caption         =   "&Help"
      Begin VB.Menu mnuInstruction
         Caption         =   "&Instructions"
      End
      Begin VB.Menu mnuAboutUs
         Caption         =   "&About Us"
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
DefLng A-Z

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public ClickCounter As Integer
Dim RndNum As Long
Private Sub ChangeCaption(index As Integer, btnCaption As String)
    If cmdChar(index).Caption = "" Then
        cmdChar(index).Caption = btnCaption
    Else
        cmdChar(index).Caption = ""
    End If
End Sub

Private Sub MatchCaption(index As Integer, btnCaption As String)
    Dim i As Integer
    Dim t As Integer
    Dim isMatch As Boolean
    i = 1
    Do While (i <= 16)
        'MsgBox "CurrentCaption : " & cmdChar(i).Caption & "btnCaption : " & btnCaption, vbInformation
        If i <> index And cmdChar(i).Caption = btnCaption Then
            'frmExplode.Show vbModal
            Sleep 200
            cmdChar(index).Visible = False
            cmdChar(i).Visible = False
            isMatch = True
        End If
        i = i + 1
    Loop
    'if not match remove all the caption except current one
    If isMatch = False Then
        i = 1
        Do While (i <= 16)
            If i <> index Then
            cmdChar(i).Caption = ""
            End If
            i = i + 1
        Loop
    End If
End Sub

Private Sub GetHighScores()
Dim objCol As New Collection
Dim objRS As New ADOR.Recordset
Dim objFSO As New FileSystemObject
Dim strScoreLine As String
Dim strPlayer As String
Dim strClicks As String
Dim i As Integer

objRS.Fields.Append "PlayerName", adVarChar, 30
objRS.Fields.Append "Clicks", adInteger
objRS.Open

'
'Dim ts As TextStream
'If Dir(App.Path & "\score.txt") <> "" Then
'    Set ts = objFSO.OpenTextFile(App.Path & "\Score.txt", ForReading)
'    Do Until ts.AtEndOfStream
'        strScoreLine = ts.ReadLine()
'        strPlayer = Split(strScoreLine, "|", , vbTextCompare)(0)
'        strClicks = Split(strScoreLine, "|", , vbTextCompare)(1)
'        objCol.Add strClicks
'    Loop
'End If
'Call DisplayHighScores(objCol)

Dim ts As TextStream
If Dir(App.Path & "\score.txt") <> "" Then
    Set ts = objFSO.OpenTextFile(App.Path & "\Score.txt", ForReading)
    Do Until ts.AtEndOfStream
        strScoreLine = ts.ReadLine()
        strPlayer = Split(strScoreLine, "|", , vbTextCompare)(0)
        strClicks = Split(strScoreLine, "|", , vbTextCompare)(1)
       
        objRS.AddNew
        objRS.Fields(0).Value = strPlayer
        objRS.Fields(1).Value = strClicks

    Loop
    objRS.Sort = "Clicks"
    If objRS.RecordCount > 0 Then
        Call DisplayHighScores(objRS)
    Else
        MsgBox "No Scores Found...!!!", vbExclamation, "Information"
    End If
Else
    MsgBox "No Scores Found...!!!", vbExclamation, "Information"
End If
End Sub

Private Sub DisplayHighScores(objRS As ADOR.Recordset)
frmHighScores.lblSno.Caption = ""
frmHighScores.lblPlayer.Caption = ""
frmHighScores.lblClicks.Caption = ""
Dim i As Integer
Dim strRow As String
'i = objRS.RecordCount
i = 0
objRS.MoveFirst
Do While i < objRS.RecordCount And i < 10
    'objRS.GetString(adClipString, i, "|")
    strRow = Replace(Trim(objRS.GetString(adClipString, 1, "|")), Chr(13), "")
    frmHighScores.lblSno.Caption = frmHighScores.lblSno.Caption & i + 1 & Chr(13)
    frmHighScores.lblPlayer.Caption = frmHighScores.lblPlayer.Caption & _
    Split(strRow, "|", , vbTextCompare)(0) & Chr(13)
    frmHighScores.lblClicks.Caption = frmHighScores.lblClicks.Caption & _
    Split(strRow, "|", , vbTextCompare)(1) & Chr(13)
    i = i + 1
Loop
frmHighScores.Show vbModal
End Sub

Private Sub cmdChar_Click(index As Integer)
Dim btnCaption As String
    ClickCounter = ClickCounter + 1
'    Select Case index
'        Case 1, 16
'        btnCaption = "F"
'        Case 2, 7
'        btnCaption = "N"
'        Case 6, 14
'        btnCaption = "R"
'        Case 3, 4
'        btnCaption = "L"
'        Case 5, 9
'        btnCaption = "S"
'        Case 8, 11
'        btnCaption = "P"
'        Case 10, 12
'        btnCaption = "B"
'        Case 13, 15
'        btnCaption = "D"
'    End Select
    btnCaption = GetCaptionByIndex(index, RndNum)
    Call ChangeCaption(index, btnCaption)
    Call MatchCaption(index, btnCaption)
    Call check
End Sub

Private Function RandomNumBetween(ByVal LowerLimit As Long, ByVal UpperLimit As Long) As Long
  ' This function returns a pseudo-random number between
  ' the specified limits (inclusive).
  RandomNumBetween = Rnd * (UpperLimit - LowerLimit) + LowerLimit
End Function

Private Sub check()
Dim objFSO As New Scripting.FileSystemObject
Dim ts As TextStream
Dim i As Integer
Dim s As Boolean
Dim strMsg As String
i = 1
s = True
     Do While (i <= 16)
     If cmdChar(i).Visible = True Then
        s = False
     End If
        i = i + 1
     Loop
If s = True Then
    Select Case ClickCounter
    Case 51 To 100
    strMsg = "Poor...!!!"
    Case 31 To 50
    strMsg = "You need some more practice...!!"
    Case 21 To 30
    strMsg = "You can do better...!!!"
    Case 16 To 20
    strMsg = "Excellent"
    End Select

    'Writing Scores
    Set ts = objFSO.OpenTextFile(App.Path & "\Score.txt", ForAppending, True, TristateUseDefault)
    ts.WriteLine strPlayerName & "|" & ClickCounter
    If MsgBox(strMsg & " You have used " & ClickCounter & " clicks !!!" & Chr(13) & _
    "Do you want to play again ?", vbYesNo, "Completed") = vbYes Then
        Call ResetGame
    End If
End If
End Sub

Private Sub ResetGame()
Dim i As Integer
i = 1
Do While (i <= 16)
    cmdChar(i).Visible = True
    cmdChar(i).Caption = ""
    i = i + 1
Loop
ClickCounter = 0
RndNum = RandomNumBetween(1, 19)
End Sub

Private Sub Form_Load()
Randomize
Dim i As Integer
i = 1

Do While (i <= 16)
    cmdChar(i).Visible = False
    cmdChar(i).Caption = ""
    cmdChar(i).FontName = "gigi"
    cmdChar(i).FontBold = True
    cmdChar(i).FontSize = 20
    i = i + 1
Loop
End Sub

Private Sub mnuAboutUs_Click()
    frnAboutUs.Show vbModal
End Sub

Private Sub mnuExit_Click()
    End
End Sub

Private Sub mnuHigh_Click()
    Call GetHighScores
End Sub

Private Sub mnuInstruction_Click()
    frmInstructions.Show vbModal
End Sub

Private Sub mnuNew_Click()
    frmEnterName.Show vbModal
    If btStartGame = True Then
    Call ResetGame
    End If
End Sub

Project Homepage: