无法从数组返回项目

Trouble returning items from an array

我刚开始使用 AHK,正在自学如何阅读包含 4 列、space 和制表符分隔符以及未知行数的文本文件。

我正在尝试获取包含字符串 "xcal" 的任何行的第一个标记,将第一个标记(%A_Index% = 1,对吗?)存储在我的数组中(RunNum ), 然后检索所有存储的数字,将它们显示在 MsgBox 中。

#SingleInstance, Force

RunNum :=  Object() ; Initialize temporary array

; ----------------- Read LIST.TAB.   ---------------------------

IfNotExist, %A_ScriptDir%\LIST.TAB
{
    MsgBox,48,Error!, LIST.TAB was not found.
        ExitApp
}
else
{
    RunCount = 1 ; Set Run counter 
    Loop, read, %A_ScriptDir%\list.tab ; Read config file
    {
        IfInString, A_LoopReadLine,  xcal ; If current line contains the word 'xcal'...
        {
            Loop, Parse, A_LoopReadLine, %A_Space% %A_Tab% ; Parse through current line of config file, space and tab delimiter 
            {
                if  (%A_Index% = 1) ; Continue if at the first element/token of string
                {   
                 RunNum[RunCount] :=  A_LoopField ; Store current field in RunNum array
                 RunCount+=1  ; Increase counter           
                }
            }               
        }                                         
    }
 MsgBox % RunNum[RunCount]
}

根据您的描述使用此数据:

1234    xcal    RandomJunk
4567    Nocal   RandomJunk
8910    xcal    RandomJunk

代码:

#SingleInstance, Force

RunNum := [] ; No reason to use Object()

; ----------------- Read LIST.TAB.   ---------------------------
If !(FileExist(A_ScriptDir "\list.tab")) {
    MsgBox,48,Error!, LIST.TAB was not found.
        ExitApp
} else {
    Loop, read, %A_ScriptDir%\list.tab ; Read config file
    {
        If (InStr(A_LoopReadLine,  "xcal")) ; If current line contains the word 'xcal'...
            RunNum.push(StrSplit(A_LoopReadLine, A_Space A_tab).1)             
    }

For Each, Value in RunNum
    YourNumbers .= Value "`n"
 MsgBox % YourNumbers
}

结果:

1234
8910