Time Delay in VB
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Time Delay in VB

  1. #1
    Join Date
    Jun 2002
    Posts
    103

    Question Time Delay in VB

    is there a function to make a time delay in vb? something like sleep(1000)?

    I tried using the timer, but it doesnt make the other processes stop and wait.

    Thanks.

  2. #2
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    17
    sure is!! Try this

    Public Sub Delay(HowLong As Date)
    Dim TempTime As Date
    TempTime = DateAdd("s", HowLong, Now)
    While TempTime > Now
    Wend
    End Sub

    All you do is send how long you want the delay to be ie:

    delay 5

  3. #3
    Join Date
    Jun 2002
    Posts
    103

    Thanks

    Thanks for your help!

  4. #4
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Private Sub Command1_Click()
    Sleep 1000
    End Sub

  5. #5
    Join Date
    Jul 2002
    Posts
    49
    Just to add some information to it. There is one limitation with the solutions given to this problem. The "sleep API" or the "while wend" method will put the application in non responding mode. i.e. if the requirement is to wait for around 30 seconds, then by using either of these methods,application will not accept any other event till the control comes out of sleep or while loop. it may affect the functionality of the application to great extent. So the user should be very careful while using these methods.

  6. #6
    Join Date
    Apr 2002
    Location
    Korean
    Posts
    26
    Some additional:

    To avoid your application seem to be dead, you can divide the delay period into a number of small intervals and then use the loop with DoEvents inside. It's something like this:

    Const Interval = 200 ' 0.2 s

    Private Sub delay(delayPeriod as Long)
    Dim delay as long

    delay = 0
    Do while (delay < delayPeriod)
    delay = delay + Interval
    DoEvents ' Process other events
    Loop
    End sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center