Solved

command botton switching

Posted on 1997-03-14
1
232 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

756 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