In the gerneral Declarations ( Second line of code, right under the Form1 header):


Dim test(4) As Image
Dim x As Integer
  • The number 4 is how many pictures you have.

Creating a Procedure.

Inside the main class you will need to create a procedure. It is a piece of code that you may want to be executed more than once. In our example when the game is over, you may want to give the user another chance to play.
Procedure make that really easy. We would give the user a mesage box asking if they want to play again, if they say yes, then we call the procedure we made, and voila the game restarts.
So here is how we make a procudure:

Near the top under the declarations of your variables write the following:

You need to set all your variables to 0

Then you should turn your pictureBox Visibility to false
Then you need to place your pictureBoxes back to where they started.

Finally turn your timers off

There is an example below:

Below the General Declarations:

Private Start()

x = 0
z = 0
PictureBox4.Visible = False
PictureBox4.left = "Put in a number here. It needs to be the x coordinate of the starting spot."

Timer1.Enabled = False
Timer2.Enabled = False

End Sub





In the form load:



test(0) = PictureBox1.BackgroundImage
test(1) = PictureBox2.BackgroundImage
test(2) = PictureBox3.BackgroundImage
test(3) = PictureBox4.BackgroundImage

Start()

  • If you have more picture continue to follow the same code.


In the Timer:


PictureBox5.BackgroundImage = test(x)
x = x + 1
If x > 3 Then
x = 0
End If

  • the number 3 has to match the amount of picture you have minus 1


In the on button:


Timer1.Enabled = True



In the off button:

Timer1.Enabled = False