Dungeon Hunter
Dungeon Hunter

Reputation: 20603

VBScript to Display Countdown using Vbscript Graphical Elements

I wanted to display a MessageBox which displays countdown from 10 to 1 and autocloses after 10 seconds. As Msgbox in vbscript passes code execution untill the user acts on it i tried it using Popup in Wscript Shell Object

Dim counter
Dim oShell
counter = 10
Set oShell= CreateObject("Wscript.Shell")
While counter > 0

oShell.Popup " Left " & counter & " Seconds",1,"Remind"
counter = counter-1
Wend

But it auto-closes for every second and opens a new popup is there any way i can display the countdown and autoclose using the available GUI elements in vb script

Upvotes: 1

Views: 21299

Answers (4)

TheRoyalOne2021
TheRoyalOne2021

Reputation: 11

It actually is possible to edit the countdown, very easily for VBScript, so I don't understand what the problem is.

Here's the code:

Dim counter
Dim oShell
counter =InputBox("")  

#if you add =InputBox you can have the choice to type in the amount of times the popup repeats#

Set oShell= CreateObject("Wscript.Shell")
While counter > 0

oShell.Popup " Time until shutdown " & counter & " Seconds",(1),"[3]Critical Viruses Detected

 #and if you change the (1) to whatever number you want then you can change how fast the popup repeats and if you join this with the "open command" then you can make a gnarly nondangerous virus#

counter = counter-1
Wend

Upvotes: 0

coder9927
coder9927

Reputation: 190

I have a code, but it might not help

    dTimer=InputBox("Enter timer interval in minutes","Set Timer") 'minutes

do until IsNumeric(dTimer)=True
  dTimer=InputBox("Invalid Entry" & vbnewline & vbnewline & _ 
         "Enter timer interval in minutes","Set Timer") 'minutes
loop
flop=InputBox("What do you want to set the timer for?")
if dTimer<>"" then
do
  WScript.Sleep dTimer*60*1000 'convert from minutes to milliseconds
Set Sapi = Wscript.CreateObject("SAPI.spVoice")
Sapi.speak "Time's up."
  t=MsgBox(flop & vbnewline & vbnewline & "Restart Timer?", _
    vbYesNo, "It's been " & dTimer &" minute(s)")
  if t=6 then 'if yes
       'continue loop
  else 'exit loop
       exit do
  end if
loop
end if

please excuse my weird variable names. This code is from https://wellsr.com/vba/2015/vbscript/vbscript-timer-with-wscript-sleep/

Upvotes: 0

MBu
MBu

Reputation: 2950

You can use Internet Explorer to create a non-modal display.

Set oIE = CreateObject("InternetExplorer.Application")

With oIE
    .navigate("about:blank")
    .Document.Title = "Countdown" & string(100, chrb(160))
    .resizable=0
    .height=200
    .width=100
    .menubar=0
    .toolbar=0
    .statusBar=0
    .visible=1
End With

' wait for page to load
Do while oIE.Busy
    wscript.sleep 500
Loop

' prepare document body
oIE.document.body.innerHTML = "<div id=""countdown"" style=""font: 36pt sans-serif;text-align:center;""></div>"

' display the countdown
for i=10 to 0 step -1
    oIE.document.all.countdown.innerText= i
    wscript.sleep 1000
next
oIE.quit

Upvotes: 2

Alex K.
Alex K.

Reputation: 175826

Afraid not, the popup is modal & can't be interacted with while its displayed so there is no way to update its existing content.

If you want a more flexible UI you will need to use something different, the console or HTML in an HTA.

Upvotes: 1

Related Questions