我如何清理这段代码使其更短? [英] How can I clean up this code to be shorter?
本文介绍了我如何清理这段代码使其更短?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用AutoIt:
I'm using AutoIt:
$1 = GetItemBySlot(1, 1)
$2 = GetItemBySlot(1, 2)
$3 = GetItemBySlot(1, 3)
$4 = GetItemBySlot(1, 4)
$5 = GetItemBySlot(1, 5)
该代码重复40行.我该如何缩短?
The code repeats for 40 lines. How can I shorten it?
推荐答案
For $i = 1 To 5
Assign($i, GetItemBySlot(1, $i))
Next
那将是3行而不是 n 行.在运行期间,它将扩展为:
That would be 3 lines instead of n lines. During runtime this will be expanded to:
Assign(1, GetItemBySlot(1, 1))
Assign(2, GetItemBySlot(1, 2))
Assign(3, GetItemBySlot(1, 3))
Assign(4, GetItemBySlot(1, 4))
Assign(5, GetItemBySlot(1, 5))
要获取这些变量的数据,您需要使用Eval
函数.所以
To get the data of those variables you need to use the Eval
function. So
For $i = 1 To 5
Eval($i)
Next
返回GetItemBySlot(1, $i)
的值.
这篇关于我如何清理这段代码使其更短?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文