Geo*_*rge 1 arrays automation autohotkey
我想问的是以下代码两个不同的数组?或者是相同的阵列?在AutoHotKey中,我很困惑如何创建两个不同的数组.我使用了一个非常老版本的AutoHotKey,版本1.0.47.06 ......
; 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"
Array@case_array_count% := 1001001
Run Code Online (Sandbox Code Playgroud)
而且,如果我有一个变量,我使用=将它分配给数组?或者使用:=?
discharge_date := "01/01/2014"
Array%date_array_count% = discharge_date
Run Code Online (Sandbox Code Playgroud)
那些不是真正的" 数组 ",它们被称为pseduo-arrays,是一种创建数组的旧方法.你可以在这里阅读更多相关信息.
在你的情况下,那些将是相同的数组,是的.您使用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%
}
Run Code Online (Sandbox Code Playgroud)
您还可以将值分配给数组,如下所示:
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
Run Code Online (Sandbox Code Playgroud)
编辑:
如果您无法升级,这就是您实现和使用多个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%
}
Run Code Online (Sandbox Code Playgroud)
如果您希望数组共享相同的索引:
; 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%
}
Run Code Online (Sandbox Code Playgroud)