hi I'm new to coding, I'm have a Visual Basic project for the memory game. it basically lets the player flips over 2 cards, if those 2 cards match, they disappear, if they don't, they flip back. the game end when all the cards disappear. I have completed the code but when I run it, it just let me flip the cards when I click; the matched cards didn't disappear, and when time out the msg box don't show up. I don't know what is wrong with my code, and Im new so I only use basic statement like if else, for next, do while,...and I use Visual Basic 2013
Please help this is my code:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    lblEasyTime.Text = Val(lblEasyTime.Text) - 1
    If lblEasyTime.Text = 0 Then Timer1.Enabled = False
End Sub
Sub check()
    'Private Sub Easy_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'Declare Variable
    Dim imgCardback(5) As PictureBox
    Dim imgCardfront(5) As PictureBox
    Dim intGuesses As Integer
    Dim intX As Integer
    Dim intY As Integer

    'Initialize variables
    imgCardback(0) = imgJHeart
    imgCardback(1) = imgJHeart2
    imgCardback(2) = imgKHeart
    imgCardback(3) = imgKHeart2
    imgCardback(4) = imgQHeart
    imgCardback(5) = imgQHeart2

    imgCardfront(0) = imgCard1
    imgCardfront(1) = imgCard2
    imgCardfront(2) = imgcard3
    imgCardfront(3) = imgcard4
    imgCardfront(4) = imgcard5
    imgCardfront(5) = imgcard6

    intGuesses = 0

    'Check images
    For intX = 0 To 5
        If imgCardfront(intX).Visible = False Then
            For intY = 0 To 5
                If imgCardfront(intY).Visible = False Then
                    If intX <> intY And imgCardback(intX).Tag = imgCardback(intY).Tag Then
                        imgCardback(intX).Visible = False
                        imgCardback(intY).Visible = False
                        imgCardfront(intX).Visible = False
                        imgCardfront(intY).Visible = False
                        intGuesses = intGuesses + 1
                    End If
                    If intX <> intY And imgCardback(intX).Tag <> imgCardback(intY).Tag And imgCardback(intX).Visible = True And imgCardback(intY).Visible = True Then
                        imgCardfront(intX).Visible = True
                        imgCardfront(intY).Visible = True
                        intGuesses = intGuesses + 1
                    End If
                End If
            Next
        End If
    Next


    If imgCard1.Visible = False And imgCard1.Visible = False And imgCard1.Visible = False And imgCard1.Visible = False And imgCard1.Visible = False And imgCard1.Visible = False And imgJHeart.Visible = False And imgJHeart2.Visible = False And imgKHeart.Visible = False And imgKHeart2.Visible = False And imgQHeart.Visible = False And imgQHeart2.Visible = False Then
        Me.Hide()
        Congratulation.Visible = True
    End If

    Do While lblEasyTime.Text = 0
        MsgBox("Times out!!! Better luck next time.")
    Loop
End Sub

Private Sub imgCard1_Click(sender As Object, e As EventArgs) Handles imgCard1.Click
    imgCard1.Visible = False
End Sub

Private Sub imgCard2_Click(sender As Object, e As EventArgs) Handles imgCard2.Click
    imgCard2.Visible = False
End Sub

Private Sub imgcard3_Click(sender As Object, e As EventArgs) Handles imgcard3.Click
    imgcard3.Visible = False
End Sub

Private Sub imgcard4_Click(sender As Object, e As EventArgs) Handles imgcard4.Click
    imgcard4.Visible = False
End Sub

Private Sub imgcard5_Click(sender As Object, e As EventArgs) Handles imgcard5.Click
    imgcard5.Visible = False
End Sub

Private Sub imgcard6_Click(sender As Object, e As EventArgs) Handles imgcard6.Click
    imgcard6.Visible = False
End Sub

Recommended Answers

All 3 Replies

Lines 59 to 61 look dangerous for any version of VB. That is, that could seems to make an infinite number of message boxes but never exits so the boxes would never show. This may be new ground for you but line 60 does not instantly put up the message. VB6 and other visual basics need to hit some idle time or encounter a DoEvents() line to let the windows messaging system process and show that message box.

commented: thank you I'll rewrite it +0

Not to mention line 54 is a mess.

commented: yeah I don't know how to make it shorter +0

Assuming this is assignment, as a former marker I would deduct points because of a complete lack of useful comments. You should get into the habit of providing a blurb for each function/method. Even if it's only for yourself, future you will thank present you for going to the effort.

commented: thank you for respond, can you tell me where are those useless comments please, I need to fix this program +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.