2014-10-08 102 views
1

我想问下面的代码是两个不同的数组?或者它是相同的数组?在AutoHotKey中我很困惑如何创建两个不同的数组。我使用的是真正的老版本的AutoHotkey的,版本1.0.47.06 ...AutoHotKey阵列混淆

; Keep track of the number of discharge cases 
date_array_count := 0 

; Keep track of the discharge cases date 
case_array_count := 0 

Array%date_array_count% := "01/01/2014" 
[email protected]_array_count% := 1001001 

,此外,如果我有一个变量,我用=将其分配到数组?或者使用:=?

discharge_date := "01/01/2014" 
Array%date_array_count% = discharge_date 

回答

5

这些都不是真正的“阵列”,他们是所谓的pseduo阵列并创建数组的老办法。你可以阅读更多有关他们here

就你而言,那些将是相同的数组,是的。您正在使用Array作为您的数组变量,而date_array_countcase_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% 
} 
+0

感谢您的好评,但它是公司软件,我无法升级。在订单版本中,是否有创建多个数组的方法? – George 2014-10-08 15:08:42

+1

@George看我的编辑。 – Sid 2014-10-08 15:23:45