Autohotkey 使用_索引或变量作为函数参数
我已经搜索了互联网/文档,似乎这是不可能的。但是我有大量的变量需要通过函数传递。该功能工作正常Autohotkey 使用_索引或变量作为函数参数,autohotkey,Autohotkey,我已经搜索了互联网/文档,似乎这是不可能的。但是我有大量的变量需要通过函数传递。该功能工作正常 Example of variable list: st1mrks = 94 st2mrks = 34 st3mrks = ... test1 = "student has collected " st1mrks " marks. " test2 = "student has collected " st2mrks " marks. " test3 = "student has collected
Example of variable list:
st1mrks = 94
st2mrks = 34
st3mrks = ...
test1 = "student has collected " st1mrks " marks. "
test2 = "student has collected " st2mrks " marks. "
test3 = "student has collected " st3mrks " marks. "
test4 = ...
或者,我尝试使用while
i=0
while (i < totaltestnumber){
dofunction(test%i%)
i++
}
i=0
while(i
但这显然行不通
还有其他方法可以做到这一点吗?让我们看看一些定义:
- 函数接受参数
- 必须始终完全定义
- i、 e.必须提前指定每个参数
- i、 e.如果有100个变量,则必须定义100个参数
- 这是因为参数成为函数内部局部变量的副本,因此需要提前完全定义
- 不是数组。它们是“顺序编号变量的集合”。
- i、 e.您有100个独立变量
- ,虽然方便,但也不建议使用
- 另一方面,是数组。它们是一个包含一系列内容的对象。
- i、 e.您有一个包含100个元素的变量
Example of variable list:
st1mrks = 94
st2mrks = 34
st3mrks = ...
test1 = "student has collected " st1mrks " marks. "
test2 = "student has collected " st2mrks " marks. "
test3 = "student has collected " st3mrks " marks. "
test4 = ...
; Create the array, initially empty:
Array := []
Loop % totaltestnumber{
Array.Push(test%A_Index%)
}
dofunction(Array)
....
dofunction(ByRef Array)
{
Loop % Array.MaxIndex()
{
...
}
}
如果从一开始就使用基于对象的数组,则可以进一步优化此代码
Example of variable list:
st1mrks = 94
st2mrks = 34
st3mrks = ...
test1 = "student has collected " st1mrks " marks. "
test2 = "student has collected " st2mrks " marks. "
test3 = "student has collected " st3mrks " marks. "
test4 = ...
; Create the array, initially empty:
Array := []
Loop % totaltestnumber{
Array.Push(test%A_Index%)
}
dofunction(Array)
....
dofunction(ByRef Array)
{
Loop % Array.MaxIndex()
{
...
}
}