Solved

command botton switching

Posted on 1997-03-14
1
230 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
ID: 1424315
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

21 Experts available now in Live!

Get 1:1 Help Now