سؤال
الجميع،
فيما يلي الرمز الذي كتبته في 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
أنا غير قادر على فهم المشكلة هنا لأن لديّ Wend و Endif لكل حلقة وحالة IF. نسيت شيئا ما هنا؟
المحلول
بما أن لديك الأمر ExitLoop
بعد then
, ، ليست هناك حاجة ل EndIf
.
(في هذا الخط: If @error = -1 Then ExitLoop
)
يمكنك إما:
مسح ال
EndIf
While 1 $currentLine = FileReadLine($fileHandle) If @error = -1 Then ExitLoop $days = StringSplit($currentLine, ",") FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF) Wend
حرك ال
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
مكان آخر.
لا تنتمي إلى StackOverflow