27162 total geeks with 3531 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
omentomikel
[b][url=http ://www.belst affforcheap. com/]belstaf f<strong><a href="http:/ /www.belstaf fforcheap.co m/">belstaff roadmaster sale</a></st rong> <br> <strong><a href="http:/ /www.belstaf fforcheap.co m/">belstaff outlet</a></ strong> <br>
omentomikel
<strong><a href="http:/ /www.belstaf fforcheap.co m/">belstaff motorcycle</ a></strong> <br> <strong><a href="http:/ /www.belstaf fforcheap.co m/">belstaff </a></strong > <br> <strong><a href="http:/ /www.belstaf fforcheap.co m/">belstaff outlet</a></ strong> <br> <br
omentomikel
[b][url=http ://www.topch ristianloubo utinsaler.ne t/]christian <strong><a href="http:/ /www.topchri stianloubout insaler.net/ ">christian louboutin shoes for cheap</a></s trong> <br> <strong><a href="http:/ /www.topchri stianloubout insaler.net/ ">christian loubouti
omentomikel
<strong><a href="http:/ /www.topchri stianloubout insaler.net/ ">christian louboutin shoes on sale</a></st rong> <br> <strong><a href="http:/ /www.topchri stianloubout insaler.net/ ">fashion christian louboutin outlet</a></ strong> <br> <strong><a href="http:/ /www.
omentomikel
[b][url=http ://www.chris tianloubouti ngmall.com/b est-seller-c -21.html]chr istia<strong ><a href="http:/ /www.christi anloubouting mall.com/bes t-seller-c-2 1.html">chri stian louboutin best sellers</a>< /strong> <br > <strong><a href="http:/ /www.christi anloubouting m

Donate
Donate and help us fund new challenges
Donate!
Due Date: Nov 30
November Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
NASA revisits
Europa with modern
image-processing
software
Sony quietly
POODLE-proofs
Playstations
Brit mobile firms
in FOURPLAY TUSSLE
? how very French
of them
Symantec reseachers
find "Regin"
malware, label it
the new Stuxnet
ESA"s spaceplane
cleared for
lift-off in
February 2015
Cloud unicorns are
extinct so DiData
cloud outage was
YOUR fault
Crypto protocols
held back by
legacy, says ENISA
Worst WordPress
hole for five years
affects 86% of
sites
Turnbull:
Box-huggers are
holding back cloud
OIF and ONF to
co-operate on
standards
Slashdot
Study: Space Rock
Impacts Not Random
How the World"s
Agricultural Boom
Has Changed CO2
Cycles
Alva Noe: Don"t
Worry About the
Singularity, We
Can"t Even Copy an
Amoeba
NASA Remasters
20-Year-Old Galileo
Photographs of
Jupiter"s Moon,
Europa
2014 Hour of Code:
Do Ends Justify
Disney Product
Placement Means?
Highly Advanced
Backdoor Trojan
Cased High-Profile
Targets For Years
Elon Musk Talks
"X-Wing" Fins For
Reusable Rockets,
Seafaring Spaceport
Drones
Blame America For
Everything You Hate
About "Internet
Culture"
Prospects Rise For
a 2015 UN Climate
Deal, But Likely To
Be Weak
Spaceport America
Loses $1.7 Million
Due To Virgin
Galactic Delays
Article viewer

How to use Pause in VB



Written by:dimport
Published by:Nightscript
Published on:2003-06-21 07:19:46
Topic:Visual Basic
Search OSI about Visual Basic.More articles by dimport.
 viewed 84218 times send this article printer friendly

Digg this!
    Rate this article :
In this tutorial, you will learn about the public sub Pause and what is it used for.

Here is the code of this public sub:

Public Sub Pause(NbSec As Single)
 Dim Finish As Single
 Finish = Timer + NbSec
 DoEvents
 Do Until Timer >= Finish
 Loop
End Sub


First of all, this Public Sub is used in order to put an interval between actions. It can be used in many situation. To use it, you need to type "pause" and "1" (for a pause of 1 second, 0.2 for a 1/5 second pause...) Let see some exemple of application:

Open a new project and add the Public Sub Pause to your code page. Then, in general section, declare the following variables:

Dim x1 As Long, x2 As Long, y1 As Long, y2 As Long, time As Byte


Now in: Form_Click paste the following code:



For time = 1 To 200
 Randomize
 x1 = Int(Rnd * 5000)
 y1 = Int(Rnd * 3000)
 x2 = Int(Rnd * 5000)
 y2 = Int(Rnd * 3000)
 Me.DrawWidth = 1
 Me.Line (x1, y1)-(x2, y2), QBColor(5)
Next time


Test it and notice the speed of the line draw. Now add
Pause 0.1
after
Me.Line (x1, y1)-(x2, y2), QBColor(5)


Test it again. You see the line are drawn slower. For and Next are one of the Pause Sub application but you can use is everywhere you want an pause between to events.



What you have learned:
  • What is the Public Sub Pause

  • How to use the Public Sub Pause




This article was originally written by Welk

Did you like this article? There are hundreds more.

Comments:
Anonymous
2006-08-11 12:43:08
I have found that this pause works but at a heavy cost. The processor goes to over 50% during the pause. That's on a system with a P4 3ghz 2GB RAM
Domuk
2006-08-11 12:52:44
Have you tried putting the DoEvents inside the Do...Loop?
Anonymous
2006-08-12 01:50:13
If all you need is a simple pause (or perhaps even complex ones) in a for loop or so.. use a Timer. You wont see any processor usage.
Anonymous
2006-12-19 04:15:30
Have you tried to use this when you go from a day to another. For example put a pause of 10 sec and start the pause at 23:59:53. The result is that you will never get out from this pause:D
Anonymous
2007-05-24 11:23:13
Try thread Sleep API sub from kernel32
Anonymous
2008-05-20 00:26:27
System.Threading.Thread.Sleep(numSec * 1000)
Anonymous
2009-12-02 16:18:55
Thanks!
Anonymous
2011-06-27 23:54:35
I still have problems with this aplication and <a href="http://www.rx-mex.com/viagra/viagra-online.html">Viagra Online</a> I simply can't do it !
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Test Yourself: (why not try testing your skill on this subject? Clicking the link will start the test.)
VB Potpourri: Programming, History And Syntax by batterseapower

A nice little collection of the basics of Visual Basic.
Advanced Programming Techniques by batterseapower

A fiendish test covering some of the more obscure elements of Visual Basic 6.


     
Your Ad Here
 
Copyright Open Source Institute, 2006