AutoIT:缺少适合的时间

时间:2010-10-29 04:43:59

标签: while-loop autoit

所有

以下是我在AutoIT中编写的代码。

    $fileToWrite = FileOpen("C:\output.txt", 1)

If FileExists("C:\test.csv") Then
    $fileHandle= FileOpen("test.csv", 0)
    If ($fileHandle = -1) Then
        MsgBox (0, "Error", "Error occured while reading the file")
        Exit
    Else
        While 1
            $currentLine = FileReadLine($fileHandle)
            If @error = -1 Then ExitLoop
            $days = StringSplit($currentLine, ",")
            FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
            EndIf
        Wend
    EndIf
Else
    MsgBox (0, "Error", "Input file does not exist")
EndIf

FileClose($fileToWrite)
FileClose($fileHandle)

错误集:

C:\ReadCSV.au3(14,4) : ERROR: missing Wend.
            EndIf
            ^
C:\ReadCSV.au3(9,3) : REF: missing Wend.
        While
        ^
C:\ReadCSV.au3(15,3) : ERROR: missing EndIf.
        Wend
        ^
C:\ReadCSV.au3(3,34) : REF: missing EndIf.
If FileExists("C:\test.csv") Then
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\ReadCSV.au3(15,3) : ERROR: syntax error
        Wend
        ^
C:\ReadCSV.au3 - 3 error(s), 0 warning(s)
>Exit code: 0    Time: 3.601

我无法理解这里的问题,因为我为每个While循环和If条件都有一个Wend和EndIf。我在这里错过了什么吗?

2 个答案:

答案 0 :(得分:2)

问题是您在Endif之前有一个WendIf已经关闭,因为那边有ExitLoop

因此,请删除Endif或将ExitLoop放在其他位置。

答案 1 :(得分:2)

由于您在ExitLoop后面有then命令,因此无需EndIf

(在此行中:If @error = -1 Then ExitLoop

你可以:

  1. 删除EndIf

    While 1
        $currentLine = FileReadLine($fileHandle)
        If @error = -1 Then ExitLoop
        $days = StringSplit($currentLine, ",")
        FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
    Wend
    
  2. ExitLoop移至下一行。 (这没有多大意义,但脚本仍会运行。)

    While 1
        $currentLine = FileReadLine($fileHandle)
        If @error = -1 Then
        ExitLoop
        $days = StringSplit($currentLine, ",")
        FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
        EndIf
    Wend
    
  3. 我会选择#1。