【问题标题】:accessing array content whithin for loop - Auto Hot Key AHK在 for 循环中访问数组内容 - Autohotkey AHK
【发布时间】:2018-12-24 20:55:20
【问题描述】:

我正在尝试将索引 i 处的数组成员的内容提取到变量中,然后将其附加到文件中。 我怎么做 ? 这是我尝试过的,但它不会占用 cgi[i]

的内容
firstrun(){
GuiControlGet, cgiDelay,,_cgiDelay
returnCode:=[]
for i in cgi {
    msg := "http://" ip "/Nexus.cgi?session=" session "&action=" firstRunCgi[i] "&tokenoverride=1"
    sendToHttp(msg)
    getRespond()
    returnCode[i]:=parseReturnCode()
    if (returnCode[i] !=0){
        addTextToGui("Setting 1st run Fail #: " i "`terrorCode: " returnCode[i] "`t"firstRunCgi[i])
        txt = `ncgi[i],skipped
        FileAppend, %txt%, cgiLog.txt
        cgi[i] :=""
        }
    else{
    ;   addTextToGui("Setting 1st run OK #: " i "`terrorCode: " returnCode[i] "`t"firstRunCgi[i])
    }
    Sleep (cgiDelay)
}

}

【问题讨论】:

    标签: arrays autohotkey


    【解决方案1】:

    现在确定为什么以及如何解决它:

                txt := "`n" cgi[i] ",skipped"
            FileAppend, %txt%, cgiLog.csv
    

    请看这里:AutoHotKey: How to access array with counter variable

    【讨论】:

      【解决方案2】:

      在您发布的示例中:For i in cgi 变量 i 包含您的键/索引,因此您可以使用键/索引访问 cgi 数组中的值:value := cgi[i]

      或者,您可以声明两个变量以在 For 循环中直接保存您的键/索引和值,如下所示:

      cgi := ["Hello", "World"]
      For i, v in cgi ; Notice the comma
           MsgBox % "This is the Key/Index: " i 
                  . "`nThis is the Value from the For loop: " v
                  . "`nThis Value was accessed using Key/Index: " cgi[i]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-10-29
        • 1970-01-01
        • 2013-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-04
        相关资源
        最近更新 更多