VB6 and Animations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cryoburned
    New Member
    • Sep 2007
    • 23

    VB6 and Animations

    What if i want to make an object tween across my form?

    I have

    [code=vb]
    While Kewlbuttons1.To p > 120
    Kewlbuttons1.To p = (Kewlbuttons1.T op - 5)
    Wend
    [/code]

    in a button, but, It just zips across insantly, leaving a black redraw space behind it.

    How can I make it smoothly and slowly, go across?
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Try putting a DoEvents inside the loop. If that doesn't work, we'll have to consider inserting a brief delay.

    Comment

    • cryoburned
      New Member
      • Sep 2007
      • 23

      #3
      Originally posted by Killer42
      Try putting a DoEvents inside the loop. If that doesn't work, we'll have to consider inserting a brief delay.
      focusing on delay, im having trouble with the timer control in my scenario. What is the proper use, and do you have an example that displays objects moving?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by cryoburned
        focusing on delay, im having trouble with the timer control in my scenario. What is the proper use, and do you have an example that displays objects moving?
        I'll have to go digging. You could try searching on a few combinations of terms here, such as "timer" and "animation" or something.

        In the meantime, you could call a function that pauses for the specified number of seconds inside your loop. The function can do something like this...
        [CODE=vb]Public Sub PauseFor(ByVal Seconds As Single)

        Dim EndTime As Date
        EndTime = DateAdd("s", Seconds, Now)
        Do
        DoEvents
        Loop Until Now >= EndTime

        End Sub[/CODE]Some things to be aware of here...
        • Since the argument is of type Single, you don't have to pass whole seconds. For instance, by passing 0.1 you could say to pause for a tenth of a second. I think.
        • Pausing for a few seconds using this routine may cause your CPU usage to look as though it's going through the roof, if you happen to look at the System Monitor (or whatever). However, since all it's doing in that loop is handing control back to Windows to do whatever (updating the display, etc.) it doesn't actually slow Windows down (at least in my experience).
        • I think there's also an API call you can do to just put this thread to sleep for a specified amount of time. Just can't remember it at the moment. It's probably called something along the lines of Sleep or Wait.

        Comment

        Working...