AutoIT:暂时缺席 Wend
所有,
下面是我在 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
我无法理解这里的问题,因为每个 While 循环都有一个 Wend 和 EndIf 以及一个 If 条件。我在这里错过了什么吗?
All,
Below is the code that I have written 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)
And the set of 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
I am not able to understand the issue here since I do have a Wend and EndIf for every While loop and an If condition. Am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于在
then
之后有命令ExitLoop
,因此不需要EndIf
。(在这一行中:
If @error = -1 then ExitLoop
)您可以:
删除
EndIf
<前><代码>同时1
$currentLine = FileReadLine($fileHandle)
如果@error = -1则退出循环
$days = StringSplit($currentLine, ",")
FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
文德
将
ExitLoop
移动到下一行。 (这没有多大意义,但脚本仍然会运行。)<前><代码>同时1
$currentLine = FileReadLine($fileHandle)
如果@error = -1 那么
退出循环
$days = StringSplit($currentLine, ",")
FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
结束如果
文德
我会选择#1。
Since you have the command
ExitLoop
after thethen
, there is no need for theEndIf
.(In this line:
If @error = -1 Then ExitLoop
)You could either:
Remove the
EndIf
Move the
ExitLoop
to the next line. (Which doesn't make a whole lot of sense, but the script will still run.)I would go with #1.
问题是您在
Wend
之前有一个Endif
,并且If
已经关闭,因为您已经结束了ExitLoop
那里。因此,要么删除
Endif
,要么将ExitLoop
放在其他地方。The problem is that you have a
Endif
before theWend
and theIf
is already closed because you haveExitLoop
over there.So either remove the
Endif
or put theExitLoop
somewhere else.