Autoit: faltando wend para enquanto
-
27-09-2019 - |
Pergunta
Tudo,
Abaixo está o código que escrevi no 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 o conjunto de erros:
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
Não sou capaz de entender o problema aqui, pois tenho um wend e endif para cada loop e uma condição IF. Estou perdendo alguma coisa aqui?
Solução
Já que você tem o comando ExitLoop
depois de then
, não há necessidade de EndIf
.
(Nesta linha: If @error = -1 Then ExitLoop
)
Você poderia:
Remova o
EndIf
While 1 $currentLine = FileReadLine($fileHandle) If @error = -1 Then ExitLoop $days = StringSplit($currentLine, ",") FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF) Wend
Mova o
ExitLoop
para a próxima linha. (O que não faz muito sentido, mas o script ainda será executado.)While 1 $currentLine = FileReadLine($fileHandle) If @error = -1 Then ExitLoop $days = StringSplit($currentLine, ",") FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF) EndIf Wend
Eu iria com o número 1.
Outras dicas
O problema é que você tem um Endif
antes de o Wend
e a If
já está fechado porque você tem ExitLoop
bem ali.
Portanto, remova o Endif
ou coloque o ExitLoop
Em outro lugar.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow