Solved

command botton switching

Posted on 1997-03-14
1
228 Views
Last Modified: 2012-06-21
I have the following program that runs a collectio of 30 files to create an animation like effect.  I would like to install a slow motion, pause and reverse effect.  I've included code for the slow motion routine.  I would like to take out the radio buttons and put in command buttons.  This way I could prees a button and run the efffect.  I could proably figure out the reverse loop.  What about pause?  How can I get the behaviour to switch when I press the buttons?

thanks


Private Sub cmdOK_Click()
    Unload Form1
End Sub

Private Sub Form_Load()
    Dim nFrame As Single
    Dim sPath As String
   
    ' Put the applications path into a variable
    sPath = App.Path
    ' Check to make sure that the path ends in a "\"
    If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
   
    ' Centre and show the form
    With Form1
        Left = (Screen.Width - Width) / 2
        Top = (Screen.Height - Height) / 2
        Show
    End With
    DoEvents
   
   
    nFrame = 1
    ' The following loop will run until the program has stopped
    ' but it will not interfere with the operation of the program
    ' at all.
    Do While DoEvents()
        ' The loop will run as long as Doevents returns non-zero.
        ' Doevents() will always return non zero if there is a
        ' form on screen that belongs to this program
   
        ' Load the next image in the sequence into the image control. The images
        ' are all held on the disk as anim0001 to anim0030. The number of the image
        ' to load is held in the nFrame variable.
       If option1 = False Then
        Image1.Picture = LoadPicture(sPath & "anim00" & Format(nFrame, "00") & ".bmp")
        nFrame = nFrame + 1
        If nFrame > 30 Then nFrame = 1
        Else
        Image1.Picture = LoadPicture(sPath & "anim00" & Format(nFrame, "00") & ".bmp")
        nFrame = nFrame + 0.1
        If nFrame > 30 Then nFrame = 1
        End If
       
       
    Loop
   
   
       
   
       
End Sub

0
Comment
Question by:johndill
1 Comment
 

Accepted Solution

by:
Mabry earned 50 total points
Comment Utility
Use this program.  You'll need to put a timer (named Timer1), picture box on your form (named Image1) and four command buttons (named cmdNormal, cmdSlow, cmdPause, cmdReverse)

I use a timer to manage the animation.  It determines WHEN the new picture is loaded.  The FrameChange variable determines which direction to go (forward = 1, reverse = -1)

I hope this helps ...

-----------------------------------

Dim nFrame As Integer
Dim FrameChange As Integer

Sub Form_Load()
    ' ensure buttons are labeled properly
    cmdNormal.Caption = "Normal"
    cmdPause.Caption = "Pause"
    cmdReverse.Caption = "Reverse"
    cmdSlow.Caption = "Slow"

    ' initialize counters
    nFrame = 1
    FrameChange = 1

    ' start animating at a normal speed    
    cmdNormal_Click
End Sub

Sub Timer1_Timer()
    Image1.Picture = LoadPicture(sPath & "anim00" _
        & Format(nFrame, "00") & ".bmp")
    nFrame = (nFrame + FrameChange + 30) Mod 30
End Sub

' Normal speed, forward
Sub cmdNormal_Click()
    Timer1.Enabled = False
    Timer1.Interval = 55
    FrameChange = 1
    Timer1.Enabled = True
End Sub

' Pause/resume animation
Sub cmdPause_Click()
    If Timer1.Enabled = False Then
        cmdPause.Caption = "Pause"
        Timer1.Enabled = True
    Else
        cmdPause.Caption = "Resume"
        Timer1.Enabled = False
    End If
End Sub

' Slow speed, forward
Sub cmdSlow_Click()
    Timer1.Enabled = False
    Timer1.Interval = 550
    FrameChange = 1
    Timer1.Enabled = True
End Sub

' Normal speed, forward
Sub cmdReverse_Click()
    Timer1.Enabled = False
    Timer1.Interval = 55
    FrameChange = -1
    Timer1.Enabled = True
End Sub

' Slow speed, reverse
Sub cmdReverseSlow_Click()
    Timer1.Enabled = False
    Timer1.Interval = 550
    FrameChange = -1
    Timer1.Enabled = True
End Sub

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now