using a command button to change what a loop is doing 
Author Message
 using a command button to change what a loop is doing

I have the following code that generates a series of 30 bitmats in an
image box for an animation like effect

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

As you can see Ive also entered an option button to make the thing
run in slow motion (change nFrame to .1 and it takes ten times longer
to complete the loop).

I would like to add a pause and rewind feature to this program but I
dont think option buttons are the way to go.  I think I could handle
the logic of reversing the loop.  How would I pause this thing.

Im trying to use command buttons but I cant get the program to jump
out of the loop when I hit a command button. So if I wanted to stop
doing this:

Image1.Picture = LoadPicture(sPath & "anim00" & Format(nFrame, "00") &
".bmp")
        nFrame = nFrame + 1
        If nFrame > 30 Then nFrame = 1

and start doing this:

Image1.Picture = LoadPicture(sPath & "anim00" & Format(nFrame, "00") &
".bmp")
        nFrame = nFrame -1
        If nFrame= 1 Then nFrame = 30

by hitting a command button what do I do

thanks in advance



Fri, 27 Aug 1999 03:00:00 GMT  
 using a command button to change what a loop is doing



:
:
: I have the following code that generates a series of 30 bitmats in an
: image box for an animation like effect
:



Fri, 27 Aug 1999 03:00:00 GMT  
 using a command button to change what a loop is doing



:
:
: I have the following code that generates a series of 30 bitmats in an
: image box for an animation like effect
:

Sorry for that other empty post. I'll try to actually answer your question
in this one. :-)

It might be easier for you to use a timer control to run your animation.

You could the animation code in the Timer event, with a static variable to
store the current frame. Use the the enabled property of the timer to start

and stop the animation. Add couple of form variables as flags to set the
speed
and direction of your animation. Then you could start the animation in your
form load, just as you're currently doing.

Another big advantage with using a timer is that the speed will be based
upon
a clock and not on the CPU performance.

--
Chris Knauft
Optitech International



Fri, 27 Aug 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Am I doing the OpenRecordset command correctly?

2. Command button stops/resumes ForNext looping?

3. Command Button won't work while in loop

4. How to break loop with command button?

5. Command Button click event as loop condition?

6. Using WhatsThisMode on command button activates button click procedure

7. This can be done by using the Visual Basic Shell command

8. Changing color of command buttons

9. Change appearance of Command Button to depressed.

10. How to change the color of command button

11. command button color changing

12. Change color of text on command button

 

 
Powered by phpBB® Forum Software