code for having a 5sec wait /sleep /pause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harshadd
    New Member
    • Dec 2007
    • 180

    code for having a 5sec wait /sleep /pause

    How do i make an execution of program wait for n seconds? where n could be any Integer..
    is there Sleep or pause or wait like command in VB6?
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by harshadd
    How do i make an execution of program wait for n seconds? where n could be any Integer..
    is there Sleep or pause or wait like command in VB6?
    I know there's sleep in VB.net,
    you can declare it:

    Public Shared Sub Sleep (millisecondsTi meout As Integer)

    it's not that hard (the only problem is that you wont be able to sleep for more than 32 seconds, because of the integers size restrictions)

    in case this doesnt help in VB6, or you need something better... hmm, may be something with DoEvents will do:

    [CODE=vb]public sub Sleep(sleepTime as single)
    dim t as single
    t= timer
    do
    doevents
    loop until (t + sleeptime >= timer)
    end sub[/CODE]

    sleepTime is in seconds ^.~

    Note: dont ever use this near midnight (hahahaha, that sounded like a gremlin), because Timer is the seconds that have passed today, so if it stills sleeping after midnight, it'll never wake up!! mua ha ha ha.
    Last edited by kadghar; Mar 11 '08, 12:41 AM. Reason: Adding a note

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      For the answer to the same question asked here recently, see this thread.

      Comment

      • harshadd
        New Member
        • Dec 2007
        • 180

        #4
        Originally posted by Killer42
        For the answer to the same question asked here recently, see this thread.
        Thanks Killer, i will check the code..

        Comment

        • anuragshrivastava64
          New Member
          • Jan 2007
          • 66

          #5
          Declare in module
          Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

          Then use it for the form
          Sleep 10000(millisec)

          Comment

          • daniel aristidou
            Contributor
            • Aug 2007
            • 494

            #6
            Originally posted by anuragshrivasta va64
            Declare in module
            Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

            Then use it for the form
            Sleep 10000(millisec)
            In vb 2008
            the code to pause a thread is simply:
            Threading.threa d.pause(1000)
            Where 1000 = milliseconds

            Comment

            Working...