Prev: Multipage userform
Next: button name scope and Caption
From: msnyc07 on 3 Apr 2010 10:31 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.
From: Mike H on 3 Apr 2010 11:12 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.
From: msnyc07 on 3 Apr 2010 11:49 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.
|
Pages: 1 Prev: Multipage userform Next: button name scope and Caption |