VBscript 循环 - 每 15 分钟报告一次时间 [英] VBscript loop - Tell time every 15 minutes

查看:35
本文介绍了VBscript 循环 - 每 15 分钟报告一次时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想要一个文件,我可以双击并让 Windows 每 15 分钟口头告诉我时间.(直到我终止进程)

I just want a file I can double-click and have Windows verbally tell me the time every 15 minutes. (Until I kill the process)

我找到了一个 VBscript 的教程,它每小时显示一次时间:https://www.nextofwindows.com/windows-trick-how-to-make-your-computer-to-speak-out-time-at-every-hour

I found this tutorial for a VBscript that tells the time every hour, on the hour: https://www.nextofwindows.com/windows-trick-how-to-make-your-computer-to-speak-out-time-at-every-hour

我无法让 Windows 调度程序使用它来满足我的目的(仅在双击时启动并每 15 分钟运行一次),老实说,我只想将一个 15 分钟间隔的循环编程到脚本本身中.(也许通过使用 Do/While 循环和 Sleep()?)

I couldn't get the Windows scheduler working with it for my purposes (start only when double-clicked and run every 15 minutes), and honestly, I just want a 15-minute-interval loop programmed into the script itself. (perhaps by using a Do/While loop and Sleep()?)

另一个问题:

我尝试添加一个分钟变量,以便 Windows 也会宣布分钟:

I tried adding a minutes variable so Windows would announce the minutes as well:

Dim speaks, speech
speaks = "It is " & hour(time) & minute(time)
Set speech = CreateObject("sapi.spvoice")
speech.Speak speaks

然而,它以一种奇怪的格式宣布时间.例如,现在是凌晨 5:01,当我运行脚本时,Windows 说现在是五十一".为什么它会将 5:01 解释为五十加一?早些时候我在 4:32 测试它时,它说四百三十二".我希望它以正常的 12 小时方式显示时间.

However, it announces the time in an odd format this way. For example, It's currently 5:01AM, and when I run the script, Windows says "It is fifty-one." Why would it interpret 5:01 as fifty plus one? Earlier when I tested it at 4:32, it said "four hundred and thirty-two." I'd like it to just state the time in a normal 12-hour fashion.

推荐答案

这需要 5 秒.所以 60 x 15 = 900.

This does 5 secs. So 60 x 15 = 900.

如果要将数字解析为单个数字,则数字之间需要空格.

You need spaces between numbers if you want them parsed as individual numbers.

Set speech = CreateObject("sapi.spvoice")
Do
    If Hour(Now) < 12 then 
        Var = Hour(Now) & " AM"
    else
        Var = Hour(Now) - 12 & " PM" 
    End If

    speech.Speak Var &  " and " & Minute(Now) & " minutes and " & Second(Now) & " seconds"
    wscript.sleep 5
Loop

这篇关于VBscript 循环 - 每 15 分钟报告一次时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆