質問

全て、

以下は、私が自動車で書いたコードです。

    $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

私はここで問題を理解することができません。なぜなら、私は毎回ループとIF条件のためにウェンドとEndifを持っているからです。ここに何かが足りませんか?

役に立ちましたか?

解決

あなたがコマンドを持っているので 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
    

#1で行きます。

他のヒント

問題は、あなたが持っていることです Endif の前に Wend そしてその If あなたが持っているので、すでに閉じられています ExitLoop そちら側。

したがって、どちらかを削除します Endif または置きます ExitLoop 何処か別の場所。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top