VB脚本逻辑错误

发布于 2024-11-04 11:25:34 字数 922 浏览 0 评论 0原文

我有以下来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我只土不豪 2024-11-11 11:25:34

ElseIf 的结构是:

If c1 Then
   ..
ElseIf c2 Then <-- Not Else
   ..
ElseIf c3 Then
   ..
Else <-- last to catch all else
   --
End If

The structure for ElseIf is:

If c1 Then
   ..
ElseIf c2 Then <-- Not Else
   ..
ElseIf c3 Then
   ..
Else <-- last to catch all else
   --
End If
暮光沉寂 2024-11-11 11:25:34

您有 3 个 End If,但只开始了 2 个 If。如果我没看错的话,您可以执行以下操作:

            For Each Modified in Files
                If IsEmpty(file1) or IsNull(file1) Then
                    file1 = Modified
                Else
                    file2 = Modified
                    If hDisk.FreeSpace > 900000000000 Then
                        Exit For
                    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
            Next

最主要的是,如果您要使用 ElseIf,则不能在 Then< 之后添加内容/code> 与 Then 位于同一行 - 仅当您的 If 语句全部包含在同一行时才能执行此操作。

You've got 3 End If's, but you're only starting 2 If's. If I'm reading this right, you could do the following:

            For Each Modified in Files
                If IsEmpty(file1) or IsNull(file1) Then
                    file1 = Modified
                Else
                    file2 = Modified
                    If hDisk.FreeSpace > 900000000000 Then
                        Exit For
                    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
            Next

The main thing being that if you are going to use the ElseIf's, you can't add the stuff after Then on the same line as the Then - you can only do that if your If statement is all contained on the same line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文