Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
hmmm ok, is there a way i can make a list and get it to randomly pick a value out, so if i add like 30 different timers to the list and then VB with randomly choose one ??
yeah, but how can i make it random choose an interval between 60000 and 900000 ??? I need it a different for everytime it moves to "next i"
Call this just before your "Next i"
VB Code:
Sub RandomizeTimer()
Randomize
Timer1.Interval = (rnd+15) +1
End Sub
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
if you run that code, it does fire the timer every minute but will only run your code randomly 1 - 15 minutes. as penagate as pointed out, the timer wont go further than just over a minute.
hmmm ok, is there a way i can make a list and get it to randomly pick a value out, so if i add like 30 different timers to the list and then VB with randomly choose one ??
Do u need a timer at all??
to make a random selection in listbox
VB Code:
List1.ListIndex = (rnd * List1.ListCount - 1) + 1
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
if you run that code, it does fire the timer every minute but will only run your code randomly 1 - 15 minutes. as penagate as pointed out, the timer wont go further than just over a minute.
casey.
Oh God!
I'hd just forgot that that property is integer.
And I think I have not understood his question clearly either.
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
yeah its not a random selection i want, it a random time between moving from on "i" to the next "i".
If u just want a random delay before "Next i" then u can loop to wait there or call the Sleep API
VB Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
yes i want a randomly delay b4 its move on to the next i. but has to be longer then 30 seconds.
Insert this before "Next i"
VB Code:
Sleep ((rnd* 90) +1 ) * 100 ''some random delay upto 90 sec, etc.
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
the problem with Sleep is it stops all code running throughout the program.
casey.
I think that's just exactly what he wants..
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
would i also have to include you code on post #13 ?? A module ? or just at the top of all the code.
Declaration on the top of form..
VB Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
And the code just before "Next i"
VB Code:
'
'
'
Sleep ((rnd* 90) +1 ) * 100 ''some random delay upto 90 sec, etc.
Next i
Pradeep
Pradeep, Microsoft MVP (Visual Basic) Please appreciate posts that have helped you by clicking icon on the left of the post.
"A problem well stated is a problem half solved." — Charles F. Kettering
Ok here's the scoop, you should never use the Sleep API to create a delay in a loop because it causes your program to halt a certain number of milliseconds, causing any code executions and events in your app to halt as well. DoEvents wouldn't even allow events to be executed either when the Sleep API is called for a long period of time. Secondly, you should never use multiple timers, or even one timer. One timer alone is slow, inaccurate, and inconsistant, and gets worse when using more timers. On top of that, when your app is used on XP and you are using a timer, timers are 10 times faster than normal, making it really inaccurate and inconsistant. The only thing that is good about a timer is the fact that it maintains low CPU usage. I recommend managed Do Loops, or While Wend loops with using either the GetTickCount API or the QueryPerformanceFrequency & QueryPerformanceCounter API's to manage it. It's higher CPU usage, but the accuracy is worth it.
Last edited by Jacob Roman; May 30th, 2005 at 07:50 AM.
I dunno, I haven't tried since managed loops came into my life after I found out the hard way back when I was addicted to Timers that Timers are really slow and inaccurate. Are those Timer API's more accurate and consistant than regular Timer objects? Have they been going 10 times faster on XP machines?
one thing u can do.. even tho itd be really inefficeint... would be to use if statements in your timer for example:
if you want such a long delay that the timer will not allow that high an interval ( it only goes up to 65000 ish) do this.
one thing u can do.. even tho itd be really inefficeint... would be to use if statements in your timer for example:
if you want such a long delay that the timer will not allow that high an interval ( it only goes up to 65000 ish) do this.
VB Code:
timer1.Interval = Int(rnd * 60000)
counter = counter + 1
If counter = 10 Then
'do whatever
End If
Guess what? That's exactly one of the reasons why API timers are used instead! See my attachment above.
Ask yourselves this question, and think about it:
If you need a random interval, why does the timer have to be precise ? ammm... random interval !!
And plus that his interval is between 1 -15 minutes, even if the timer is inacurate to 1 second, why does it matter when the interval is RANDOM ?
The timer is inacurate for couple of milliseconds (10-20 milliseconds), so why worry ?
Here's the code I sugest to use:
(Put a timer on the form)
I wasn't arguing, sorry if it came across that way. I was pointing out that since the instrinsic Timer control's Interval property is a short Integer you can't actually specify an interval of 15 minutes, hence the use of an API timer.
Ask yourselves this question, and think about it:
If you need a random interval, why does the timer have to be precise ? ammm... random interval !!
And plus that his interval is between 1 -15 minutes, even if the timer is inacurate to 1 second, why does it matter when the interval is RANDOM ?
The timer is inacurate for couple of milliseconds (10-20 milliseconds), so why worry ?
Here's the code I sugest to use:
(Put a timer on the form)
VB Code:
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 500
Timer1.Enabled = True
Randomize
End Sub
Private Sub Timer1_Timer()
Static PrevTime As Single, TmrInterval As Single
If PrevTime = 0 And TmrInterval = 0 Then
PrevTime = Timer
TmrInterval = (840 * Rnd) + 60
End If
If (PrevTime + TmrInterval) < Timer Then
DoYourThing
PrevTime = Timer
TmrInterval = (840 * Rnd) + 60
End If
End Sub
Private Sub DoYourThing()
' pick a value from your list here...
Debug.Print Timer
End Sub
cheers this looks useful, DoYourThing is where put the code i want the program to do ? which is do webbrowser navigate to blah & list1.list(i) next i .
cheers this looks useful, DoYourThing is where put the code i want the program to do ? which is do webbrowser navigate to blah & list1.list(i) next i .
Yup... don't worry about previous posts, you don't need precision for what you have to do... just put code in the "DoYourThing" sub...