473,395 Members | 1,530 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,395 software developers and data experts.

Help with loops.

devonknows
137 100+
Hi, im making a loop that opens several pages into internet explorer, using the tabs, but to stop it from causing too much lagg i want to make the loop wait 200ms each time.

this is the loop im using, do i need to use a timer inside the loop or add something to the function it calls?

any help you can give ill most appreciative,

Kind Regards
Devon.

Expand|Select|Wrap|Line Numbers
  1. Do While Not getsd.EOF
  2.             If sitesopened <= maxsites Then
  3.                 replacementtext = Replace(Text1.Text, " ", getsd!keywordsplitmarker)
  4.                 endcommand = getsd!endcommandstring
  5.                 ShellExecute hwnd, "open", getsd!WebSiteSearchAddress & replacementtext & endcommand, vbNullString, vbNullString, SW_SHOW
  6.                 getsd.MoveNext
  7.                 sitesopened = sitesopened + 1
  8.                 lastsearch = Text1.Text
  9.             Else
  10.                 If maxsitereached = 1 Then
  11.                     getsd.MoveNext
  12.                 Else
  13.                     MsgBox "Your Current Settings do not allow for you to go above " & maxsites & " sites," & vbCrLf & "You can change this in the settings menu.", vbInformation, "Information!"
  14.                     maxsitereached = 1
  15.                     getsd.MoveNext
  16.                 End If
  17.             End If
  18.         Loop
  19.  
Dec 4 '06 #1
3 2172
Killer42
8,435 Expert 8TB
I'd suggest you create a Public sub called something like Pause, which you can reuse. In there, you can do a number of things to waste time. For example...
Expand|Select|Wrap|Line Numbers
  1. Public Sub Pause (ByVal Seconds As Double)
  2.   Dim StartTime As Double, EndTime As Double
  3.   StartTime = Timer
  4.   EndTime = Timer + Seconds
  5.   Do
  6.     DoEvents
  7.   Loop until ( Timer > EndTime ) Or ( Timer < StartTime )
  8. End Sub
Note, the "< StartTime" is to prevent an "infinite" loop if you pass midnight. The value in Timer clocks over at midnight.

Don't forget the DoEvents in there, to let Windows get on with things and avoid locking everything up.

To pause for 200 ms, just code Pause 0.2
Dec 6 '06 #2
This is a routine which uses the Windows API sleep function to sleep the program.

put the declare statement in the beginning of the module where you add the sleep subroutine

It doesn't tie up the CPU for other conncurrent applications while the thread is sleeping

call the sleep module as follows



Expand|Select|Wrap|Line Numbers
  1.  
  2.     Public Declare Sub sapiSleep Lib "kernel32" Alias "Sleep" _
  3.         (ByVal dwMilliseconds As Long)
  4.  
  5. Sub Sleep(lngMilliSec As Long)
  6.     If lngMilliSec > 0 Then
  7.         Call sapiSleep(lngMilliSec)
  8.     End If
  9. End Sub
  10.  
Dec 7 '06 #3
This is a routine which uses the Windows API sleep function to sleep the program.

put the declare statement in the beginning of the module where you add the sleep subroutine

It doesn't tie up the CPU for other conncurrent applications while the thread is sleeping

call the sleep module as follows

Sleep 200

sleeps the program for 200 milliseconds

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Public Declare Sub sapiSleep Lib "kernel32" Alias "Sleep" _
  3.         (ByVal dwMilliseconds As Long)
  4.  
  5. Sub Sleep(lngMilliSec As Long)
  6.     If lngMilliSec > 0 Then
  7.         Call sapiSleep(lngMilliSec)
  8.     End If
  9. End Sub
  10.  
  11.  
Dec 7 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: chahnaz.ourzikene | last post by:
Hi all, This is the first i post in this newsgroup, i hope my english is not too bad... Let's get straight to the point ! I have a little probleme using threads in my little training example :...
7
by: mx2k | last post by:
Hello @ all, we have written a small program (code below) for our own in-developement rpg system, which is getting values for 4 RPG-Characters and doing some calculations with it. now we're...
0
by: Paolo Tavalazzi | last post by:
I have a problem on FROM subselect that i don't understand. I do two query different only for a WHERE clause in a FROM subquery . 1) explain analyze SELECT DISTINCT ON...
2
by: bitong | last post by:
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are...
8
by: Dameon99 | last post by:
my program compiles without problems but when i try to run it pauses shortly and then crashes. When i set it to debug it came up with the following message: "An Access Violation (Segmentation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.