Delay Function in VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    Delay Function in VB6

    Hello all,
    I want to put delay in my loops as we use in c/c++..
    Is there any delay function in vb6 which put delay between any code???

    Thanx
    >> ALI <<
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    #2
    Originally posted by Ali Rizwan
    Hello all,
    I want to put delay in my loops as we use in c/c++..
    Is there any delay function in vb6 which put delay between any code???

    Thanx
    >> ALI <<
    Try:

    system.threadin g.thread.sleep( miliseconds)

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by jamesd0142
      Try:

      system.threadin g.thread.sleep( miliseconds)
      I wouldn't try that in VB6, you might hurt yourself. :)

      You might want to look into API calls such as SleepEx.

      As for plain VB, I used to have a simple routine I wrote for jsut this kind of situation. I'll throw together another one now. Note that you would be better off finding a way to call the Windows "put this thread to sleep" function(s). Looping and calling DoEvents from VB causes a bit of an odd situation. It appears to chew up a huge amount of CPU. But since all it's doing is telling Windows repeatedly to "ignore me and go do your own thing" it doesn't (as far as I can tell) slow anything down. In other words, if you hear the CPU fan rev up, or see your CPU monitor suddenly hit 50% or 100%, don't panic. :)

      [CODE=vb]Public Sub SleepFor(ByVal Seconds As Double)
      ' "Sleep" for the specified number of seconds.
      Dim EndTime As Date
      EndTime = DateAdd("s", Seconds, Now)
      Do
      DoEvents
      Loop Until Now >= EndTime
      End Sub
      [/CODE]Note: I wrote this in VB6 IDE just now, so the syntax should be correct. But it hasn't been tested.

      to use it, just code
      [CODE=vb]SleepFor 1.5 ' Pause for 1½ seconds.
      [/CODE]

      Comment

      • Ali Rizwan
        Banned
        Contributor
        • Aug 2007
        • 931

        #4
        Thanx for helping me.
        >> ALI <<

        Comment

        Working...