這些都不是真正的「陣列」,他們是所謂的pseduo陣列並創建數組的老辦法。你可以閱讀更多有關他們here。
就你而言,那些將是相同的數組,是的。您正在使用Array
作爲您的數組變量,而date_array_count
和case_array_count
作爲索引。兩者都是零,所以你把兩個值放在同一個索引處,這意味着你會覆蓋你的第一個值。
至於分配值,請嘗試始終使用:=
。當你想分配一個字符串時,引用這樣的字符串:myVariable := "Hello world!"
。
「真實」陣列添加到AHK在以後的版本,我強烈建議您升級到。你可以從這裏獲取最新版本 - http://ahkscript.org/
一旦你有了最新的版本,你可以在文檔閱讀更多關於陣列 - http://ahkscript.org/docs/misc/Arrays.htm
這裏有一個如何使用數組一個基本的例子:
; Create an array
myArray := []
; Add values to the array
myArray.insert("cat")
myArray.insert("dog")
myArray.insert("dragon")
; Loop through the array
for each, value in myArray {
; each holds the index
; value holds the value at that index
msgBox, Ittr: %each%, Value: %value%
}
; Get a specific item from the array
msgBox % myArray[2]
; Remove a value from the array at a set index
myArray.remove(1)
; Loop through the array
for each, value in myArray {
; each holds the index
; value holds the value at that index
msgBox, Ittr: %each%, Value: %value%
}
您還可以將值分配給數組是這樣的:
index := 1
myVariable := "my other value"
myArray[index] := "my value" ; Puts "my value" at index "1" in the array
myArray[index] := myVariable ; Puts "my other value" at index "1" in the array
編輯:
如果您無法升級,你這是怎麼實現,並與多個工作pseduo陣列:如果你想陣列共享相同的
; Create our index variables
dateIndex := 0
caseIndex := 0
; Create our two arrays
dateArray := ""
caseArray := ""
; Increment the index before adding a value
dateIndex++
; Add values to the array using the index variable
dateArray%dateIndex% := "01/01/2014"
caseIndex++
caseArray%caseIndex% := 1001001
; Loop through the array, use the index as the loop-count
Loop % dateIndex
{
; A_Index contains the current loop-index
msgBox % dateArray%A_Index%
}
Loop % caseIndex
{
msgBox % caseArray%A_Index%
}
而且索引:
; Create index variable
arrIndex := 0
; Create our two arrays
dateArray := ""
caseArray := ""
; Increment the index before adding a value
arrIndex++
; Add values to the array using the index variable
dateArray%arrIndex% := "01/01/2014"
caseArray%arrIndex% := 1001001
arrIndex++
dateArray%arrIndex% := "02/02/2014"
caseArray%arrIndex% := 999999
; Loop through the array, use the index as the loop-count
Loop % arrIndex
{
; A_Index contains the current loop-index
msgBox % dateArray%A_Index% "`n" caseArray%A_Index%
}
來源
2014-10-08 15:06:37
Sid
感謝您的好評,但它是公司軟件,我無法升級。在訂單版本中,是否有創建多個數組的方法? – George 2014-10-08 15:08:42
@George看我的編輯。 – Sid 2014-10-08 15:23:45