How do you go about pausing your code from operating. I want to make an animation by making a picture box visable then another then another but I need a period of time between transitions? How would I go about doing this?

boredPic(1, 1).Visible = True
boredPic(1, 1).Image = My.Resources.Red
     'pause for half a second then
boredPic(1, 1).Visible = false
boredPic(2, 1).Visible = True
boredPic(2, 1).Image = My.Resources.Red
    'pause again for half a second
etc 

You could do something like this...

Dim stpWatchInfo As New System.Diagnostics.Stopwatch

boredPic(1, 1).Visible = True
boredPic(1, 1).Image = My.Resources.Red
     'pause for half a second then
stpWatchInfo.Restart()
while stpWatchInfo.Elapsed.TotalMilliseconds<500
'this is a 500 millisecond pause or 1/2 second

End While

boredPic(1, 1).Visible = false
boredPic(2, 1).Visible = True
boredPic(2, 1).Image = My.Resources.Red
    'pause again for half a second
stpWatchInfo.Restart()
while stpWatchInfo.Elapsed.TotalMilliseconds<500
    'this is a 500 millisecond pause or 1/2 second

End While
etc

That may work for you. let me know if you need more help or it doesn't work correctly.
Larry

You use a timer to track time and run the next thing when you want it to.
But... you don't want to "pause" your program or have the timer loop for a period, becuase if I am not mistaken that will freeze your main thread and no animation will show.
Use multi-threading or background worker for the timer and the track of time.
I'm sure you'll find lots of tutorials in here.

You can pause your application (the example here is for half a second) by

System.Threading.Thread.Sleep(500)

but what would be the point? All that you do is make your app unresponsive for the sleep time. VB programs are event driven. If you want some event to occur at set intervals then create a timer control and set the interval for the appropriate number of milliseconds. Put the code you want to execute in the timer Tick event.

Is there a way of playing the timer tick though in the middle of code being run? so the code will stop, run the timer(showing the animation or the picture box) then go back to the code and carry on till the end?

You have to break up your code into subs. Each sub can be executed when a timer expires. You can't pause your code and have it continue to execute at the same time.

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.