VBScript 使用 Vbscript 图形元素显示倒计时

发布于 2024-12-27 10:49:06 字数 397 浏览 2 评论 0原文

我想显示一个 MessageBox,它显示从 10 到 1 的倒计时,并在 10 秒后自动关闭。由于 vbscript 中的 Msgbox 传递代码执行直到用户对其进行操作,我尝试使用 Wscript Shell 对象中的 Popup 进行操作,

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

但它每秒自动关闭并打开一个新的弹出窗口,有什么方法可以使用可用的 GUI 显示倒计时和自动关闭vb脚本中的元素

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

污味仙女 2025-01-03 10:49:06

您可以使用 Internet Explorer 创建非模式显示。

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

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
情独悲 2025-01-03 10:49:06

不用担心,弹出窗口是模态的,并且是模态的。显示时无法与之交互,因此无法更新其现有内容。

如果您想要更灵活的 UI,您将需要使用不同的东西,即 HTA 中的控制台或 HTML。

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.

软甜啾 2025-01-03 10:49:06

我有一个代码,但它可能没有帮助

    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

,请原谅我奇怪的变量名称。
此代码来自 https://wellsr.com/vba /2015/vbscript/vbscript-timer-with-wscript-sleep/

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/

夜空下最亮的亮点 2025-01-03 10:49:06

实际上可以编辑倒计时,对于 VBScript 来说非常容易,所以我不明白问题是什么。

这是代码:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文