# Visual Basic 2008 - Help with Flow of program



## dancswdevils (Jun 27, 2008)

hello, below is a snippet of a program i am writing, a memory game. You click on a box to see a picture then you click on a 2nd box and see if the picture matches. The problem I am having is that on the 2nd click, the box is not displaying the picture until after all the IF THEN statements have been run. I'm pretty inexperienced so any help would be appreciated. Thanks

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

PictureBox1.Image = Image.FromFile("c:\match game\cover\" & oneone & ".bmp")
counter = counter + 1


If counter Mod 2 <> 0 Then
temp1 = oneone
firstclick = "oneone"
End If

If counter Mod 2 = 0 Then
PictureBox1.Image = Image.FromFile("c:\match game\cover\" & oneone & ".bmp")
temp2 = oneone
If temp1 = temp2 Then
timekiller()
turnover1(temp1, temp2, oneone, onetwo, onethree, onefour, onefive, onesix)
turnover2(temp1, temp2, twoone, twotwo, twothree, twofour, twofive, twosix)
turnover3(temp1, temp2, threeone, threetwo, threethree, threefour, threefive, threesix)
turnover4(temp1, temp2, fourone, fourtwo, fourthree, fourfour, fourfive, foursix)
turnover5(temp1, temp2, fiveone, fivetwo, fivethree, fivefour, fivefive, fivesix)
End If

If temp1 <> temp2 Then
secondclick = "oneone"
timekiller()
backover(firstclick, secondclick)
End If
End If
End Sub


----------



## jamiemac2005 (Jul 5, 2007)

Read next post....v


----------



## jamiemac2005 (Jul 5, 2007)

Sorry, i'm trying to work out exactly what your program is actually doing.. ignore what i just said, it's useless... If you could comment out your code (with what "oneone"'s value is) and what "counter" is initialized as (0/1) then it would help loads( i believe the problem may be in your modification of "counter"

Cheers,
Jamey


----------



## dancswdevils (Jun 27, 2008)

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

PictureBox1.Image = System.Drawing.Image.FromFile("c:\match game\cover\" & oneone & ".bmp") 'changes picturebox image from the back of a card to the front
counter = counter + 1 'Counter =0 on form_load, everytime a picturebox is clicked (there are 30 of them) counter increases by 1

If counter Mod 2 = 1 Then 'if i'm not mistaken the only 2 answers could be 1 or 0, if the answer is 1 then it means that only 1 picturebox has been clicked
temp1 = oneone 'oneone is an integer variable that holds a number from 1 to 15. Its the value of the card that is displayed in the picturebox. Each picturebox has its own variable (oneone, onetwo...) I transfered the value of oneone to temp1 so I can compare the value of the two pictureboxes that will be clicked

End If

If counter Mod 2 = 0 Then 'if this statement is true then a second picturebox has been clicked

temp2 = oneone 'transfers the value of the card shown in picturebox1 to temp2

If temp1 = temp2 Then 'if the value of the cards that were clicked are the same then run the code below
timekiller() 'I put this here or else the 2nd picturebox that the person clicks on would change to the back of the card before you get a chance to see it. It is just a loop that takes about 2 seconds to complete
turnover1(temp1, temp2, oneone, onetwo, onethree, onefour, onefive, onesix) 'these next 5 subprocedures turn the visiblity to false on the 2 pictureboxes that were clicked
turnover2(temp1, temp2, twoone, twotwo, twothree, twofour, twofive, twosix)
turnover3(temp1, temp2, threeone, threetwo, threethree, threefour, threefive, threesix)
turnover4(temp1, temp2, fourone, fourtwo, fourthree, fourfour, fourfive, foursix)
turnover5(temp1, temp2, fiveone, fivetwo, fivethree, fivefour, fivefive, fivesix)
End If

If temp1 <> temp2 Then Reset() 'if the 2 cards that were clicked do not equal then I want to turn the pictures back to a picture of the back of the deck. The reset sub procedure contains 2 porcedures 1. timekiller() and 2. backover() which goes through all the pictureboxes and changes the image to the back of the deck

End If
End Sub



When I test the program I always use picturebox2 as my 1st click and picturebox1 as my second. I added a label to see what was happening when i ran the program. I had the label display what the counter was at different stages. I put the label right under the counter=counter+1. I ran the program and clicked picturebox2 then clicked picturebox1 and the program displayed the counter result in the label after it performed the timekiller procedure (the timekiller procedure that runs if temp1<>temp2)


----------



## jamiemac2005 (Jul 5, 2007)

I can't find a problem within your code,

i have two questions though:

1) do you use the procedure PictureBox1_Click to handle all the picture boxes' click event?
2) does the timekiller event run a loop or use an interval? you'd be better to be linking the function with time so that it doesn't rely on the cpu's speed to slow the appication... I assume timekiller() should link to a "Timer" object... If you don't understand me then you'll have to google (because my knowledge of VB is not great enough to help you out.

Cheers,
Jamey


----------

