Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Does exist a timer function

Reply
 
Old 07-06-2009   #1 (permalink)
Marco Mangiante


 
 

Does exist a timer function

Hello to everyone,

is there a timer function in vbs/vb that give me the opportunity, for
example in a loop, to set a time, say 5 minutes, and then start an event?

I created a script to do a ping to an host: what I'd like to do
programmatically is start a ping every 5 minutes or so.

Someone has any idea?

--
Regards,

Marco Mangiante

My System SpecsSystem Spec
Old 07-06-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Does exist a timer function


"Marco Mangiante" <MarcoMangiante@xxxxxx> wrote in
message news:17ED8595-9E4D-4562-8DD2-B690B24DA759@xxxxxx
Quote:

> Hello to everyone,
>
> is there a timer function in vbs/vb that give me the opportunity, for
> example in a loop, to set a time, say 5 minutes, and then start an event?
>
> I created a script to do a ping to an host: what I'd like to do
> programmatically is start a ping every 5 minutes or so.
>
> Someone has any idea?
>
> --
> Regards,
>
> Marco Mangiante
Perhaps like so:
do
YourPingFunction
wscript.sleep 300000
loop


My System SpecsSystem Spec
Old 07-08-2009   #3 (permalink)
mr_unreliable


 
 

Re: Does exist a timer function

Marco Mangiante wrote:
Quote:

> is there a timer function in vbs/vb that give me the opportunity, for
> example in a loop, to set a time, say 5 minutes, and then start an event?
>
hi Marco,

As has already been said, you can use sleep and then "wake up"
to send your ping.

But, if you are courageous enough, or foolhardy enough, to use
a 3rd party control, then you could make use of a "real" system
timer. One big advantage of a system timer is that your script
can run (doing "real work") and then get interrupted periodically
by the system timer.

One such timer, packaged as an actX object, is Steve McMahon's
SSubTmr control, found here:

http://www.vbaccelerator.com/home/VB...er/article.asp

Note that the title of that page is "Subclassing without Crashes",
but the SSubTmr control also contains a timer.

Here is how to use Steve's timer in script (assuming you have
downloaded it and registered it:

Dim oTMR : Set oTMR + WScript.CreateObject("SSubTimer.CTimer", "oTMR_")

Set the interval and turn on the timer:

oTMR.Interval = 2000

Your timer event handler:

Sub oTMR_ThatTime() ' timer event...

..do some stuff
End Sub

When finished, turn off your timer:
oTMR.Interval = 0 ' make sure timer is OFF...
Set oTMR = nothing

That's all there is (for this one). There are probably others.

There are also "high-resolution" timers, but that's another
subject.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)

p.s. Cautionary note: It almost goes without saying, BUT...
the code in your timer event handler should be very brief
-- and particularly so if the timer interval is short.
For example, if your timer event handler takes a while to
run, and if the interval is so short that another timer
event fires while the event handler is still not finished
with processing the previous event, then you have overlapping
event processing, which cascades down into chaos. If this
happens, it is unlikely you will ever recover, and the
symptom you will see shortly is "out of stack space"...




My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Egg Timer Vista General
RC2 Egg Timer Vista General
BUG: Redirecting function contents to a file truncates function lines at the width of the console PowerShell
Egg timer on XP Vista General
Egg Timer Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46