ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Random Running of a Script? (https://www.excelbanter.com/excel-programming/441298-random-running-script.html)

msnyc07

Random Running of a Script?
 
I have a script that I'd like to run randomly between X and Y minutes.

Is there a way to make a small function to call that function randomly in
that time frame? Ideally I could also push yet another random # into it.

Thanks in advance.

Mike H

Random Running of a Script?
 
Hi,

There are several ways of initiating this, here's one. assuming your
'script' is called MySub then to gererate the random number of minutes we use
the formula

x=Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

where you substitute upperbound and lowerbound with the upper and lower
minutes. So the code looks like this and when run once it will recursively
call itself every x minutes.

Sub MySub()

'Your Code

x = Int((10 - 1 + 1) * Rnd + 1)
Application.OnTime Now + TimeValue("00:" & x & " :00"), "MySub"
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"msnyc07" wrote:

I have a script that I'd like to run randomly between X and Y minutes.

Is there a way to make a small function to call that function randomly in
that time frame? Ideally I could also push yet another random # into it.

Thanks in advance.


msnyc07

Random Running of a Script?
 
Many thanks!

"Mike H" wrote:

Hi,

There are several ways of initiating this, here's one. assuming your
'script' is called MySub then to gererate the random number of minutes we use
the formula

x=Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

where you substitute upperbound and lowerbound with the upper and lower
minutes. So the code looks like this and when run once it will recursively
call itself every x minutes.

Sub MySub()

'Your Code

x = Int((10 - 1 + 1) * Rnd + 1)
Application.OnTime Now + TimeValue("00:" & x & " :00"), "MySub"
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"msnyc07" wrote:

I have a script that I'd like to run randomly between X and Y minutes.

Is there a way to make a small function to call that function randomly in
that time frame? Ideally I could also push yet another random # into it.

Thanks in advance.



All times are GMT +1. The time now is 09:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com