Random Running of a Script?

  • Thread starter Thread starter msnyc07
  • Start date Start date
M

msnyc07

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.
 
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.
 
Many thanks!

Mike H said:
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.
 
Back
Top