开发者

VB script logic error

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 f开发者_如何学Goile1.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'


The structure for ElseIf is:

If c1 Then
   ..
ElseIf c2 Then <-- Not Else
   ..
ElseIf c3 Then
   ..
Else <-- last to catch all else
   --
End 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜