Pregunta

Todo,

A continuación se muestra el código que he escrito en 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)

Y el conjunto de error:

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

Yo no soy capaz de entender el problema aquí, ya que tienen un Wend y EndIf Si bien para cada bucle y un If condición. Me estoy perdiendo algo aquí?

¿Fue útil?

Solución

Dado que usted tiene la ExitLoop comando después del then, no hay necesidad de que el EndIf.

(En esta línea: If @error = -1 Then ExitLoop)

Usted podría:

  1. Eliminar el EndIf

    While 1
        $currentLine = FileReadLine($fileHandle)
        If @error = -1 Then ExitLoop
        $days = StringSplit($currentLine, ",")
        FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
    Wend
    
  2. Mueva el ExitLoop a la siguiente línea. (Lo cual no tiene mucho sentido, pero el guión seguirá funcionando.)

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

Me gustaría ir con # 1.

Otros consejos

El problema es que usted tiene una Endif antes de la Wend y la If ya está cerrado porque tiene ExitLoop por allí.

Así que eliminar ya sea el Endif o poner el ExitLoop en otro lugar.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top