Time 操作员突然停止工作

Time 操作员突然停止工作,time,vbscript,operators,Time,Vbscript,Operators,一周前我写了这个脚本,它在你登录时启动,然后根据一天中的时间向你打招呼。今天早上,它突然说:“时间无效”(如果所有其他elseif选项与时间不匹配,它就会这样做)。这以前一直有效到今天 这是我的密码: Set objShell = CreateObject("WScript.Shell") ctime = Time() usr = objShell.ExpandEnvironmentStrings("%username%") if ctime > "06:00:00" and ctime

一周前我写了这个脚本,它在你登录时启动,然后根据一天中的时间向你打招呼。今天早上,它突然说:“时间无效”(如果所有其他
elseif
选项与时间不匹配,它就会这样做)。这以前一直有效到今天

这是我的密码:

Set objShell = CreateObject("WScript.Shell")
ctime = Time()
usr = objShell.ExpandEnvironmentStrings("%username%")
if ctime > "06:00:00" and ctime < "12:00:00" then
    objShell.Popup "Good Morning, " & usr, 5, "", 4096
elseif ctime > "12:00:00" and ctime < "18:00:00" then
    objShell.Popup "Good Afternoon, " & usr, 5, "", 4096
elseif ctime > "18:00:00" and ctime < "23:59:59" then
    objShell.Popup "Good evening, " & usr, 5, "", 4096
elseif ctime > "00:00:00" and ctime < "06:00:00" then
    objShell.Popup "Good night, " & usr, 5, "", 4096
else
    objShell.Popup "Invalid time", 5, "", 4096
end if
Set objShell=CreateObject(“WScript.Shell”)
ctime=时间()
usr=objShell.expandEnvironmentString(“%username%”)
如果ctime>“06:00:00”和ctime<“12:00:00”,则
弹出“早上好,&usr,5,”,4096
如果ctime>“12:00:00”和ctime<“18:00:00”,则
弹出“下午好,&usr,5,”,4096
如果ctime>“18:00:00”和ctime<“23:59:59”那么
弹出“晚上好,&usr,5,”,4096
如果ctime>“00:00:00”和ctime<“06:00:00”,则
弹出“晚安,&usr,5,”,4096
其他的
弹出“无效时间”,5,“,4096
如果结束

编辑:现在已经10点了,但由于某种原因,它在10点之前没有工作,我想我的代码中仍然有一个错误?

您正在比较时间和字符串数据子类型的值。关于它(或关于自动数据子类型转换)的定义有点不清楚;我猜转换为字符串的时间使用另一种前导零操作,例如
#09:10:12
时间转换为
“9:10:12”
“9:10:12”
字符串。因此,通过将时间文字括在数字符号(
)中,强制使用时间文字进行时间比较,例如
\06:00:00
,而不是
“06:00:00”

但是,您的逻辑仍然存在漏洞:例如
#06:00:00#
#12:00:00#
#18:00:00#
时间与任何
if
elseif
条件不匹配,并将给出无效的时间输出

因此

if ctime > "06:00:00" and ctime < "12:00:00" then
如果ctime>“06:00:00”和ctime<“12:00:00”,则
使用其中一个

if ctime >= #06:00:00# and ctime < #12:00:00# then
如果ctime>=#06:00:00#和ctime<#12:00:00#那么


如果ctime>#06:00:00#和ctime感谢您的回答,这对我帮助很大!
if ctime > #06:00:00# and ctime <= #12:00:00# then