Domanda

Tutti,

Di seguito è riportato il codice che ho scritto in 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)

E l'insieme di errore:

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

io non sono in grado di capire il problema qui da quando ho un Wend e EndIf per ogni While e una condizione if. Mi sto perdendo qualcosa qui?

È stato utile?

Soluzione

Dal momento che hai il comando ExitLoop dopo la then, non v'è alcuna necessità per il EndIf.

(In questa linea: If @error = -1 Then ExitLoop)

Si potrebbe o:

  1. Rimuovere il EndIf

    While 1
        $currentLine = FileReadLine($fileHandle)
        If @error = -1 Then ExitLoop
        $days = StringSplit($currentLine, ",")
        FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
    Wend
    
  2. Spostare il ExitLoop alla riga successiva. (Che non fa un sacco di senso, ma lo script sarà ancora eseguito.)

    While 1
        $currentLine = FileReadLine($fileHandle)
        If @error = -1 Then
        ExitLoop
        $days = StringSplit($currentLine, ",")
        FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
        EndIf
    Wend
    

vorrei andare con # 1.

Altri suggerimenti

Il problema è che si dispone di un Endif prima della Wend e la If è già chiuso perché avete ExitLoop laggiù.

Quindi, rimuovere sia il Endif o mettere la ExitLoop da qualche altra parte.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top