Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems running a dos program from vba script Reh Excel Programming 7 November 27th 06 10:20 PM
Running a script while editing a cell clayton Excel Discussion (Misc queries) 8 December 15th 05 10:24 PM
Running a Script upon Saving a File Michael Excel Programming 3 September 12th 05 07:36 PM
running vbs script from vba? John Gunn Excel Programming 1 November 13th 04 01:08 AM
Running a VB Script Sofia Katchi Excel Programming 2 July 17th 03 03:22 PM


All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"