Solved

command botton switching

Posted on 1997-03-14
1
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…

736 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