473,549 Members | 5,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 46044

"Stephen Williams" <st*****@hotmai l.com> wrote in message
news:%O******** ************@ne ws02.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*****@hotmai l.com> wrote in message
news:%O******* *************@n ews02.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*********@em ail.address> wrote in message
news:q7******** *************** *********@4ax.c om...
"...And the next sign of the Apocalypse will be..."
*****
On Fri, 13 Feb 2004 09:38:32 GMT, Raoul Watson wrote:

"Stephen Williams" <st*****@hotmai l.com> wrote in message
news:%O******* *************@n ews02.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*****@Intell igenCIA.com> wrote in message
news:oA******** ********@nwrdny 02.gnilink.net. ..

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

"Stephen Williams" <st*****@hotmai l.com> wrote in message
news:%O******* *************@n ews02.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*****@hotmai l.com> wrote in message news:<pc******* *************@n ews02.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*****@hotmai l.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
1870
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 to be perfect. For example, I'd be happy with something where there was at most one pause per second, each pause was less than .2 seconds, and half...
3
2909
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 sbfrmAnswers. I put an option group (optAnswers) on the subform with buttons for true or false. To speed entry of the results of the 350+ surveys...
11
39868
by: Paminu | last post by:
Is there something like system("PAUSE") for linux?
8
36422
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 seems to work. But I have no clue how to pause/suspend the process. As far as I can see the Process class doesn't offer anything for this. So it's...
11
2603
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
3972
by: Jackie | last post by:
I just want the programme to stop for a while. Thanks.
6
4044
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 using indy sockets, and can send information ok
8
11386
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> #include<cstdlib> #include<string> main(){
3
2600
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 to continue. The first time that the pause button is clicked, the rotation stops and all is well. Click again and the rotation continues. But then...
5
6473
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
7526
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7480
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7814
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5373
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.