Vbscript VBS错误溢出:';WScript.Sleep';。作为警报的脚本

Vbscript VBS错误溢出:';WScript.Sleep';。作为警报的脚本,vbscript,Vbscript,我已经写了这篇文章,我不断得到相同的错误,我不知道为什么,但在测试vbs文件中,它工作正常 它应该做的是取一个数字,在上午9点输入9,并将其转换为秒,然后通过从86400取当前时间(以秒为单位),即24*60*60,将其添加到到达午夜所需的时间。数学证明了这一点,我只是不明白这个错误意味着什么,或者我无法发现错误 这是一个有效的测试 Dim sglTimer usertime = InputBox("What time? (in hours from 12)") usersectime = u

我已经写了这篇文章,我不断得到相同的错误,我不知道为什么,但在测试vbs文件中,它工作正常

它应该做的是取一个数字,在上午9点输入9,并将其转换为秒,然后通过从86400取当前时间(以秒为单位),即24*60*60,将其添加到到达午夜所需的时间。数学证明了这一点,我只是不明白这个错误意味着什么,或者我无法发现错误

这是一个有效的测试

Dim sglTimer

usertime = InputBox("What time? (in hours from 12)")
usersectime = usertime * 60 * 60
sglTimer = timer
tf = 86400
timeaway = tf-timer
totimeaway = usersectime + timeaway
mstotimeaway = totimeaway * 1000
WScript.Sleep mstotimeaway
MsgBox("woop")
这是应该是功能齐全的,但我一直在犯睡眠错误

Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim sglTimer
Dim batName
Dim statusCode
Dim returntext
Dim isitok
Dim usertime
Dim usersectime
Dim tf
Dim timeaway
Dim totimeaway
Dim mstotimeaway

returntext = InputBox("What time do you wish to wake up at", "How long?", "60", 150, 150)

If IsNumeric(returntext) Then
    isitok = MsgBox("Is " & returntext & " minuites OK?", vbOKCancel)
    returntext = returntext * 1000 * 60
    If isitok = 1 Then
        usertime = returntext
        usersectime = usertime * 60 * 60
        sglTimer = timer
        tf = 86400
        timeaway = tf-timer
        totimeaway = usersectime + timeaway
        mstotimeaway = totimeaway * 1000
        MsgBox("Started coutdown, in the background.")
        WScript.Sleep mstotimeaway

        WshShell.SendKeys("^{Esc}")
        WScript.Sleep 1000
        WshShell.SendKeys("chrome")
        WScript.Sleep 2000
        WshShell.SendKeys("{Enter}")
        WScript.Sleep 10000
        WshShell.SendKeys("https://www.youtube.com/watch?v=VRDEWANy6P8")
        WScript.Sleep 1000
        WshShell.SendKeys("{Enter}")
        WScript.Sleep 1000
    Else
        batName = "C:\Users\The_SUDO\Desktop\ALARM!!!.vbs"
        statusCode = WshShell.Run(batName, 1, True)
    End If
Else
    batName = "C:\Users\The_SUDO\Desktop\ALARM!!!.vbs"
    statusCode = WshShell.Run(batName, 1, True)
End If

在代码中,您可以将用户输入转换两次:

returntext=returntext*1000*60
usertime=returntext
usersectime=usertime*60*60

WScript.Sleep
的最大值取决于脚本主机版本。如果乘以1000两次,可能会超过最大值。

您希望输入什么?问题是一小时值(上午9点),但代码似乎需要几分钟
returntext*1000*60
会将分钟转换为毫秒。啊,是的,这是一个错误,我稍后会看看是否有修复。感谢与错误无关,但根据我的经验,
WScript。睡眠对于更大的时间跨度来说不是很可靠。短时间的循环睡眠直到时间限制通常对我更有效。还有,有什么特别的原因让你想自己执行调度而不是使用任务调度器吗?这是一个很好的观点哈哈谢谢:)是的,我认为睡眠功能不允许它,即使计算是一次哈哈,我的意思是我在做时很累,所以我没有想太多。我想我本可以使用其中一个ping睡眠循环,但谢谢你的回复:)