访问循环中的数组内容-自动热键AHK

时间:2018-07-17 08:25:32

标签: arrays autohotkey

我试图将索引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)
}

}

2 个答案:

答案 0 :(得分:0)

现在确定原因和方式,但是可以解决此问题:

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

参见此处:AutoHotKey: How to access array with counter variable

答案 1 :(得分:0)

在示例中,您发布了: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]