How to pause the code in VB 
July 17th, 2005, 09:41 PM
| | | |
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? | 
July 17th, 2005, 09:41 PM
| | | | 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 | 
July 17th, 2005, 09:41 PM
| | | | 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. | 
July 17th, 2005, 09:41 PM
| | | | 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.) | 
July 17th, 2005, 09:41 PM
| | | | 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 | 
July 17th, 2005, 09:41 PM
| | | | 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 | 
July 17th, 2005, 09:43 PM
| | | | 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. | 
July 17th, 2005, 09:43 PM
| | | | 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. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|