Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.VBS equivalent of a .HTA countdown timer 1

Status
Not open for further replies.

Lokoono

Programmer
Jun 13, 2007
34
US
I'm trying to create an equivalent of a HTA timer I found some months back. I've revised the code below to fit my needs with HTA (though the 10 seconds part is only to show that it works in a quick fashion).

Here's my question:

Is it possible to get a .vbs equivalent? I don't need a GUI (so no HTA), but would rather like the code to run in the background and repeat itself every 5 minutes (it would serve as a reminder system for myself). I haven't seen any examples of this on experts-exchange (I've searched keywords of 'countdown' and 'timer' and found no such luck for an actual .vbs file).

Can anyone help? Thanks!

Here's the HTA code. I tried several variations, but I can't figure out how to loop a timer for just vbs.

Code:
<html>
<head>
<title>Test HTA</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Test HTA"
     BORDER="thin"
     SCROLL="yes"
     SINGLEINSTANCE="no"
     WINDOWSTATE="normal"
>
</head>

<script language="VBScript">

' Declare global variable outside the Subs
Dim intMinutes
Dim intSeconds

Sub Window_onLoad
      intWidth = 800
      intHeight = 600
      Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
      intMinutes = 1
      intSeconds = 0
      iTimerID = window.setInterval("CloseWindow", 1000)
End Sub

Sub CloseWindow
      If intSeconds = 0 Then
            If intMinutes = 0 Then
msgbox "This message will repeat in another 10 seconds"
            Else
                  intMinutes = intMinutes - 1
            End If
            intSeconds = 10
      Else
            intSeconds = intSeconds - 1
      End If
      span_clock.innerHTML = intMinutes & ":" & Right("00" & intSeconds, 2)
End Sub

</script>

<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')">
      <table width='90%' height = '100%' align='center' border='0'>
            <tr>
                  <td align="center" colspan="2">
                        <h2>Test HTA</h2>
                  </td>
            </tr>
            <tr>
                  <td align='center'>
                        <input type='button' value='Close' name='btnClose' id='btnClose' onClick='vbs:window.close'>
                  </td>
            </tr>
            <tr>
                  <td>
                        <span id="span_clock">
                              0:10
                        </span>
                  </td>
            </tr>
      </table>

</body>
</html>
 
Have a look at the WScript.Sleep method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV, thanks for the response. I did originally look at WScript.Sleep, but didn't think that worked for looping. I haven't gotten it to work. I've seen examples elsewhere on the net, but WScript.Sleep doesn't seem to do anything with the code I used.

Below is the code I had typed for my vbs script sorry I forgot to include it originally). Again, it doesn't loop like its supposed to.

I tried it with Msgbox too, and it didn't work that way either...the msgbox actually disappears automatically, so that's why I went for the Popup.


Code:
Dim Msg
Msg="This message will re-appear in 10 seconds"
i=0
Do While i=0
dim objDOS
set objDOS = CreateObject ("WScript.Shell")
objDOS.Popup Msg
WScript.Sleep (10000)
Loop
 
Actually, nevermind my question. I found a good workaround. I don't know how many resources having a continual looping script would use anyway, so I guess this new way is safer.

What I did was create a custom HTA dialog box (that looks like a fancy message box) and have it called up via the Scheduled Tasks program in Windows. It works great for me.

Thanks anyway. :eek:)
 
run the following with CScript.exe:
Code:
Dim Msg
Msg="This message will re-appear in 10 seconds"
i=0
Do While i=0
WScript.Echo Msg
WScript.Sleep 10000
Loop

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top