Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2004, 11:52 PM
Authorized User
 
Join Date: Jan 2004
Posts: 34
Thanks: 0
Thanked 1 Time in 1 Post
Default Add a Pause

I am making an application to flip a coin. I have 3 pictures of a coin (heads, side, tails) and want to create an animation of the coin flipping. I need to have pauses so the animation goes slow enough to see. I tried creating a large loop to put between each picture, but it didn't work. Does anyone have any ideas on how to make a pause?
 
Old January 31st, 2004, 01:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jlick
Default

Well, probably the easiest thing to do is to create an animation with animation software, and just play it.

But to make a pause, I assume that the coin flip is in a custom control or on a form. So add a timer. You can set the amount of time you want between events. Then when the timer event triggers, just go to the next frame. This is better than a loop, because a loop will go at different speeds on different computers. This would go at the same speed as long as the computer can keep up with your pause.

John R Lick
[email protected]
 
Old January 31st, 2004, 12:29 PM
Authorized User
 
Join Date: Jan 2004
Posts: 34
Thanks: 0
Thanked 1 Time in 1 Post
Default

I went to help and copied the code that was there for timer (removing unnecessary parts and changing it from 5 seconds to 1 second). I tried to run the program, but when I clicked the button to "flip" the coin the program froze. Here is my code I used to test the timer.

Code:
Public Sub OneSecond()

        Dim Start, Finish As Double
            Start = Microsoft.VisualBasic.DateAndTime.Timer
        Finish = Start + 1.0   ' Set end time for 1-second duration.
            Do While Microsoft.VisualBasic.DateAndTime.Timer < Finish

            Loop

    End Sub


    Public Sub Flipper()

        CoinSide.Visible = True 'Show the side view of the coin
        OneSecond() 'Wait one second
        CoinSide.Visible = False 'Hide the side view of the coin
        CoinTails.Visible = True 'Show the tails side of the coin
        OneSecond()
        CoinTails.Visible = False 'Hide the tails side  of the coin
        CoinHeads.Visible = True 'Show the heads side of the coin
        OneSecond()
        CoinHeads.Visible = False 'Hide the heads side of the coin
        OneSecond()

    End Sub

    Private Sub btnFlip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFlip.Click

        Flipper()

    End Sub
 
Old February 1st, 2004, 12:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jlick
Default

You are trying to control the timing with the wrong thing. (I.e. you are mis-using the timer.) The time should be the thing in control.

Try out the following code:
You should add a timer to a new form in a new app.
Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ' Put your code in here to flip to the next frame of your video.

        Debug.Write(" Timer Click: " & Now().ToString & vbCrLf)
    End Sub


This will write out a note every time the timer clicks. You can control how often the timer clicks by changing the interval property of the timer. You can control if the timer is on by changing the enabled property.

The function that gets called by the timer's click should check which side is visible, and make it the next side.

John R Lick
[email protected]





Similar Threads
Thread Thread Starter Forum Replies Last Post
How Can I Pause Loop dsmike2008 VB How-To 5 July 18th, 2008 01:01 PM
Pause between macros paul20091968 Access VBA 2 April 6th, 2007 01:40 AM
Pause Code stealthdevil Access VBA 5 February 5th, 2007 12:48 PM
"Pause" Checking ... tonyrosen Excel VBA 2 November 23rd, 2005 11:02 AM
Pause Printing rajanikrishna Pro VB 6 0 November 28th, 2004 09:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.