424,279 Members | 1,907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,279 IT Pros & Developers. It's quick & easy.

How to pause the code in VB

P: 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?
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"Stephen Williams" <st*****@hotmail.com> wrote in message
news:%O********************@news02.tsnz.net...
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?


Simple enough..

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

Jul 17 '05 #2

P: n/a
"...And the next sign of the Apocalypse will be..."
*****
On Fri, 13 Feb 2004 09:38:32 GMT, Raoul Watson wrote:

"Stephen Williams" <st*****@hotmail.com> wrote in message
news:%O********************@news02.tsnz.net...
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?


Simple enough..

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


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

P: n/a

"Auric__" <no*********@email.address> wrote in message
news:q7********************************@4ax.com...
"...And the next sign of the Apocalypse will be..."
*****
On Fri, 13 Feb 2004 09:38:32 GMT, Raoul Watson wrote:

"Stephen Williams" <st*****@hotmail.com> wrote in message
news:%O********************@news02.tsnz.net...
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?


Simple enough..

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


Why not just While Timer < later! ?


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

P: n/a

"Raoul Watson" <Wa*****@IntelligenCIA.com> wrote in message
news:oA****************@nwrdny02.gnilink.net...

"Auric__" <no*********@email.address> wrote in message
news:q7********************************@4ax.com...
"...And the next sign of the Apocalypse will be..."
*****
On Fri, 13 Feb 2004 09:38:32 GMT, Raoul Watson wrote:

"Stephen Williams" <st*****@hotmail.com> wrote in message
news:%O********************@news02.tsnz.net...
> 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?
>

Simple enough..

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


Why not just While Timer < later! ?


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


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
Jul 17 '05 #5

P: n/a
"Stephen Williams" <st*****@hotmail.com> wrote in message news:<pc********************@news02.tsnz.net>...
<cut>
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.


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
Jul 17 '05 #6

P: n/a


Bob Butler wrote:
for a 2 second wait just use the sleep api call

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

sleep 2000

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.

Jul 17 '05 #7

P: n/a
On Fri, 13 Feb 2004 22:30:33 +1300, "Stephen Williams"
<st*****@hotmail.com> wrote:
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.


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.
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.