473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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?
Jul 17 '05 #1
7 46032

"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
"...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

"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

"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
"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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew | last post by:
When will .NET have a low-pause-time garbage collector A low-pause-time garbage collector would greatly improve .NET's ability to serve as a platform for soft real-time systems. It doesn't have...
3
by: jdph40 | last post by:
In Access 2002, I designed a simple database for our Safety department to enter results of a survey. There are 41 true/false statements. I have a main form called frmSurvey with a subform called...
11
by: Paminu | last post by:
Is there something like system("PAUSE") for linux?
8
by: Wim | last post by:
My GUI application starts a process (a console program) when the user hits Play. I would like to add an option to pause that process. The code I've added to detect if the user hit pause/unpause...
11
by: Paul Mars | last post by:
How to pause in the middle of a sub? I can not use a timer. The Sub can not be broken in two. tx, paul
38
by: Jackie | last post by:
I just want the programme to stop for a while. Thanks.
6
by: Peted | last post by:
Hi wondering what is the best way to do this Need a user to click a button, that sends 3 or 4 string based commands via a TCP/ip socket link I can connect to the ip device no problems, am...
8
by: Lloydm | last post by:
I've used the command "pause" in batch files which works ok but I guess it's applied dirrently in c++. Using Dev C++ 4.0 and the following is my code #include<iostream> #include<iomanip>...
3
by: garfunkel214 | last post by:
I have images and text rotating every 7000 ms using a setInterval. i am trying to implement a pause button that will stop the rotation when clicked. When clicked once more, I would like the rotation...
5
by: CoderMarc | last post by:
Hi, I can not get the system pause to work in a simple program. Here is my program below: // i/o example #include <iostream> using namespace std; int main ()
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.