How to pause the code in VB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Williams

    How to pause the code in VB

    I want to add a 2 secondish pause to a program, i can't find any nice and
    easy commands that will do it. I looked at the timer control but i can't
    seem to see how it will help.

    Any ideas?


  • Raoul Watson

    #2
    Re: How to pause the code in VB


    "Stephen Williams" <stevexc@hotmai l.com> wrote in message
    news:%O0Xb.2396 3$ws.2965880@ne ws02.tsnz.net.. .[color=blue]
    > I want to add a 2 secondish pause to a program, i can't find any nice and
    > easy commands that will do it. I looked at the timer control but i can't
    > seem to see how it will help.
    >
    > Any ideas?
    >[/color]

    Simple enough..

    later! = Timer + 2 'about 2 secs
    While now! < later!
    DoEvents
    now! = Timer
    Wend



    Comment

    • Auric__

      #3
      Re: How to pause the code in VB

      "...And the next sign of the Apocalypse will be..."
      *****
      On Fri, 13 Feb 2004 09:38:32 GMT, Raoul Watson wrote:
      [color=blue]
      >
      >"Stephen Williams" <stevexc@hotmai l.com> wrote in message
      >news:%O0Xb.239 63$ws.2965880@n ews02.tsnz.net. ..[color=green]
      >> I want to add a 2 secondish pause to a program, i can't find any nice and
      >> easy commands that will do it. I looked at the timer control but i can't
      >> seem to see how it will help.
      >>
      >> Any ideas?
      >>[/color]
      >
      >Simple enough..
      >
      >later! = Timer + 2 'about 2 secs
      > While now! < later!
      > DoEvents
      > now! = Timer
      >Wend[/color]

      Why not just While Timer < later! ?
      --
      auric "underscore " "underscore " "at" hotmail "dot" com
      *****
      The smoker you drink, the player you get.

      Comment

      • Raoul Watson

        #4
        Re: How to pause the code in VB


        "Auric__" <not.my.real@em ail.address> wrote in message
        news:q78p20lga4 cg8031cl8e438be imagfkt2g@4ax.c om...[color=blue]
        > "...And the next sign of the Apocalypse will be..."
        > *****
        > On Fri, 13 Feb 2004 09:38:32 GMT, Raoul Watson wrote:
        >[color=green]
        > >
        > >"Stephen Williams" <stevexc@hotmai l.com> wrote in message
        > >news:%O0Xb.239 63$ws.2965880@n ews02.tsnz.net. ..[color=darkred]
        > >> I want to add a 2 secondish pause to a program, i can't find any nice[/color][/color][/color]
        and[color=blue][color=green][color=darkred]
        > >> easy commands that will do it. I looked at the timer control but i[/color][/color][/color]
        can't[color=blue][color=green][color=darkred]
        > >> seem to see how it will help.
        > >>
        > >> Any ideas?
        > >>[/color]
        > >
        > >Simple enough..
        > >
        > >later! = Timer + 2 'about 2 secs
        > > While now! < later!
        > > DoEvents
        > > now! = Timer
        > >Wend[/color]
        >
        > Why not just While Timer < later! ?[/color]

        For clarity of code
        (also as a habit to ensure that we're comparing like variables.)


        Comment

        • Stephen Williams

          #5
          Re: How to pause the code in VB


          "Raoul Watson" <WatsonR@Intell igenCIA.com> wrote in message
          news:oAgXb.1923 8$M8.100@nwrdny 02.gnilink.net. ..[color=blue]
          >
          > "Auric__" <not.my.real@em ail.address> wrote in message
          > news:q78p20lga4 cg8031cl8e438be imagfkt2g@4ax.c om...[color=green]
          > > "...And the next sign of the Apocalypse will be..."
          > > *****
          > > On Fri, 13 Feb 2004 09:38:32 GMT, Raoul Watson wrote:
          > >[color=darkred]
          > > >
          > > >"Stephen Williams" <stevexc@hotmai l.com> wrote in message
          > > >news:%O0Xb.239 63$ws.2965880@n ews02.tsnz.net. ..
          > > >> I want to add a 2 secondish pause to a program, i can't find any nice[/color][/color]
          > and[color=green][color=darkred]
          > > >> easy commands that will do it. I looked at the timer control but i[/color][/color]
          > can't[color=green][color=darkred]
          > > >> seem to see how it will help.
          > > >>
          > > >> Any ideas?
          > > >>
          > > >
          > > >Simple enough..
          > > >
          > > >later! = Timer + 2 'about 2 secs
          > > > While now! < later!
          > > > DoEvents
          > > > now! = Timer
          > > >Wend[/color]
          > >
          > > Why not just While Timer < later! ?[/color]
          >
          > For clarity of code
          > (also as a habit to ensure that we're comparing like variables.)
          >
          >[/color]

          Thanks guys, i forgot completey about that timer. I was trying to figure it
          out using the timer control and i knew there had to be an easier way.

          Thanks again.

          Steve


          Comment

          • Bob Butler

            #6
            Re: How to pause the code in VB

            "Stephen Williams" <stevexc@hotmai l.com> wrote in message news:<pczXb.242 16$ws.3001015@n ews02.tsnz.net> ...
            <cut>[color=blue]
            > Thanks guys, i forgot completey about that timer. I was trying to figure it
            > out using the timer control and i knew there had to be an easier way.[/color]

            the timer function resets at midnight so your app can get locked up if
            you are unlucky enough to start your wait at 23:59:59; it's not likely
            but it can happen

            for a 2 second wait just use the sleep api call

            Private Declare Sub Sleep Lib "kernel32" _
            (ByVal dwMilliseconds As Long)

            sleep 2000

            Comment

            • Miles

              #7
              Re: How to pause the code in VB



              Bob Butler wrote:[color=blue]
              > for a 2 second wait just use the sleep api call
              >
              > Private Declare Sub Sleep Lib "kernel32" _
              > (ByVal dwMilliseconds As Long)
              >
              > sleep 2000[/color]


              That is a far better way than waiting with a Do/Loop as suggested. The
              Sleep API call will release CPU time back to windows. The Do/Loop
              suggestion will cause CPU usuage to hit 100% while in the loop.

              Comment

              • J French

                #8
                Re: How to pause the code in VB

                On Fri, 13 Feb 2004 22:30:33 +1300, "Stephen Williams"
                <stevexc@hotmai l.com> wrote:
                [color=blue]
                >I want to add a 2 secondish pause to a program, i can't find any nice and
                >easy commands that will do it. I looked at the timer control but i can't
                >seem to see how it will help.
                >[/color]

                Timer1.Interval = 0.1
                Timer1.Enabled = True
                FinishedTime = DateAdd( "s", 2, Now )
                While Now < FinishedTime
                WaitMessage ' an API
                DoEvents
                Wend
                Timer1.Enabled = False

                The Timer pulses a Windows message to your App

                WaitMessage 'idles' your App and does not return until there is a
                Windows message to process

                DoEvents keeps your App responding

                The problem with omitting the WaitMessage is that your App is
                hammering away inside the loop - wasting CPU time

                The problem with Sleep( N ) is that for N seconds your App is simply
                'dead' to the world

                WaitMessage without the Timer pulse would only check for the elapsed
                period /after/ a Windows message - and if you leave the mouse and
                keyboard alone, this could be a very long time.


                Comment

                Working...