VB脚本逻辑错误
我有以下来自 vbscript 的代码片段:
For Each Modified in Files
If IsEmpty(file1) or IsNull(file1) Then
file1 = Modified
Else
file2 = Modified
If hDisk.FreeSpace > 900000000000 Then Exit For
ERROR HERE-->ElseIf file2.DateLastModified < file1.DateLastModified And DateDiff("D", file2.DateLastModified, Now) > 7 Then file2.Delete
ElseIf file1.DateLastModified < file2.DateLastModified And DateDiff("D", file1.DateLastModified, Now) > 7 Then
file1.Delete
file1 = Modified
End If
End If
End If
Next
当我尝试编译脚本时,收到一条错误,指出缺少“结束”,更具体地说是预期“结束”代码 800A03F6。
我已经对代码进行了多次梳理,似乎无法弄清楚为什么它会给出这个错误。是的,我还尝试使用“End”而不是“End If”
I have the following snippet of code from a vbscript:
For Each Modified in Files
If IsEmpty(file1) or IsNull(file1) Then
file1 = Modified
Else
file2 = Modified
If hDisk.FreeSpace > 900000000000 Then Exit For
ERROR HERE-->ElseIf file2.DateLastModified < file1.DateLastModified And DateDiff("D", file2.DateLastModified, Now) > 7 Then file2.Delete
ElseIf file1.DateLastModified < file2.DateLastModified And DateDiff("D", file1.DateLastModified, Now) > 7 Then
file1.Delete
file1 = Modified
End If
End If
End If
Next
When I try to compile the script, I get an error that I'm missing an 'End', more specifically Expected 'End' Code 800A03F6.
I've combed over the code several times and can't seem to figure out why it's giving my this error. And yes, I also tried the using 'End' as opposed to 'End If'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ElseIf 的结构是:
The structure for ElseIf is:
您有 3 个
End If
,但只开始了 2 个If
。如果我没看错的话,您可以执行以下操作:最主要的是,如果您要使用
ElseIf
,则不能在Then< 之后添加内容/code> 与
Then
位于同一行 - 仅当您的If
语句全部包含在同一行时才能执行此操作。You've got 3
End If
's, but you're only starting 2If
's. If I'm reading this right, you could do the following:The main thing being that if you are going to use the
ElseIf
's, you can't add the stuff afterThen
on the same line as theThen
- you can only do that if yourIf
statement is all contained on the same line.