【问题标题】:VBscript - multiline IF statement yielding error [duplicate]VBscript - 多行 IF 语句产生错误 [重复]
【发布时间】:2021-01-16 03:18:12
【问题描述】:

我有一个基本脚本可以运行一年没有问题。最近,我尝试在其中添加IF 语句,因此如果当前日期是一年中的特定日期,即 1 月 18 日,则不要使用 Msgbox。我认为这会相当简单,但在 IF 语句的第一行遇到了Sub or Function not defined,我似乎无法自己解决:

If Not CStr(Date()) Like  "1/18/*" _ 
And Not CStr(Date()) Like "2/15/*" _
And Not CStr(Date()) Like "12/31/*" Then
MsgBox "perform task"
Else
MsgBox "do not perform task"
End If

谁能告诉我我错过了什么?

【问题讨论】:

标签: date if-statement vbscript


【解决方案1】:

VBScript 中没有 Like 运算符。实现您想要做的事情的一种方法是:

MonthAndDay = Month(Date) & "/" & Day(Date)

If MonthAndDay <> "1/18" _
   and MonthAndDay <> "2/15" _
   and MonthAndDay <> "12/31" Then
   MsgBox "perform task"
Else
   MsgBox "do not perform task"
End If

【讨论】:

    猜你喜欢
    • 2017-02-06
    • 2015-03-01
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    相关资源
    最近更新 更多