AutoIT:暂时缺席 Wend

发布于 2024-09-29 20:51:52 字数 1283 浏览 4 评论 0原文

所有,

下面是我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

硪扪都還晓 2024-10-06 20:51:52

由于在 then 之后有命令 ExitLoop,因此不需要 EndIf

(在这一行中:If @error = -1 then ExitLoop

您可以:

  1. 删除EndIf

    <前><代码>同时1
    $currentLine = FileReadLine($fileHandle)
    如果@error = -1则退出循环
    $days = StringSplit($currentLine, ",")
    FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
    文德

  2. 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 the then, there is no need for the EndIf.

(In this line: If @error = -1 Then ExitLoop)

You could either:

  1. Remove the EndIf

    While 1
        $currentLine = FileReadLine($fileHandle)
        If @error = -1 Then ExitLoop
        $days = StringSplit($currentLine, ",")
        FileWrite($fileToWrite,$days[2] & ", " & $days[9] & @CRLF)
    Wend
    
  2. Move the ExitLoop to the next line. (Which doesn't make a whole lot of sense, but the script will still run.)

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

I would go with #1.

筱武穆 2024-10-06 20:51:52

问题是您在 Wend 之前有一个 Endif,并且 If 已经关闭,因为您已经结束了 ExitLoop那里。

因此,要么删除 Endif,要么将 ExitLoop 放在其他地方。

The problem is that you have a Endif before the Wend and the If is already closed because you have ExitLoop over there.

So either remove the Endif or put the ExitLoop somewhere else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文