Connecting Tech Pros Worldwide Help | Site Map

How to pause the code in VB

  #1  
Old July 17th, 2005, 09:41 PM
Stephen Williams
Guest
 
Posts: n/a
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?


  #2  
Old July 17th, 2005, 09:41 PM
Raoul Watson
Guest
 
Posts: n/a

re: How to pause the code in VB



"Stephen Williams" <stevexc@hotmail.com> wrote in message
news:%O0Xb.23963$ws.2965880@news02.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



  #3  
Old July 17th, 2005, 09:41 PM
Auric__
Guest
 
Posts: n/a

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@hotmail.com> wrote in message
>news:%O0Xb.23963$ws.2965880@news02.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.
  #4  
Old July 17th, 2005, 09:41 PM
Raoul Watson
Guest
 
Posts: n/a

re: How to pause the code in VB



"Auric__" <not.my.real@email.address> wrote in message
news:q78p20lga4cg8031cl8e438beimagfkt2g@4ax.com...[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@hotmail.com> wrote in message
> >news:%O0Xb.23963$ws.2965880@news02.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.)


  #5  
Old July 17th, 2005, 09:41 PM
Stephen Williams
Guest
 
Posts: n/a

re: How to pause the code in VB



"Raoul Watson" <WatsonR@IntelligenCIA.com> wrote in message
news:oAgXb.19238$M8.100@nwrdny02.gnilink.net...[color=blue]
>
> "Auric__" <not.my.real@email.address> wrote in message
> news:q78p20lga4cg8031cl8e438beimagfkt2g@4ax.com...[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@hotmail.com> wrote in message
> > >news:%O0Xb.23963$ws.2965880@news02.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


  #6  
Old July 17th, 2005, 09:41 PM
Bob Butler
Guest
 
Posts: n/a

re: How to pause the code in VB


"Stephen Williams" <stevexc@hotmail.com> wrote in message news:<pczXb.24216$ws.3001015@news02.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
  #7  
Old July 17th, 2005, 09:43 PM
Miles
Guest
 
Posts: n/a

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.

  #8  
Old July 17th, 2005, 09:43 PM
J French
Guest
 
Posts: n/a

re: How to pause the code in VB


On Fri, 13 Feb 2004 22:30:33 +1300, "Stephen Williams"
<stevexc@hotmail.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.


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pause doesn't work in vb.net James answers 2 November 13th, 2007 04:25 PM
pause the execution of code in one routine while letting the app respond to keyboard Frank answers 18 January 18th, 2007 04:15 PM
DoEvents in VB.NET Julia Beresford answers 5 March 23rd, 2006 10:05 AM
I can't operate anything in VB.NET Mamatha answers 6 November 21st, 2005 04:07 AM