How to use counters with variables, error: %%, Autohotkey
How to use counters with variables, error: %%, Autohotkey
在一个循环中我想使用一个计数器来使用不同的变量。
问题是两者都使用 % 符号:%VAR%
显示错误 %%,已简化:
textGH1 = Peter
textGH2 = rocks.
i = 1
Loop, 2
{
SendInput {Enter}
Sleep 50
SendInput, %textGH%i%%
Sleep 50
SendInput {Enter}
i++
}
错误:空变量引用 %%
我尝试了什么:
我已经查找了 autohotkey 的数组,但我只找到了
使用 %COUNTER% 作为解决方法的伪数组,类似于我的方法
做到了。其次,我已将循环中的一个变量分配给您当前的变量:
text := textGH%i%
然而,这并没有像预期的那样调用变量(再次需要 %textGH%i%%)
这应该有效:
SendInput, %textGH%%i%
我想我明白你在做什么?当计数器改变时交换变量。最简单的方法是使用数组。
这里有一个解决方案供您尝试:
Define Array. Array's Index values automatically, so Peter is at Index 1 Rocks is at Index 2.
MyArray := ["Peter", "Rocks"]
Loop amount of times as there are Values in your Array.
Loop, % MyArray.MaxIndex() {
SendInput {Enter}
Sleep 50
Send your Array at [Index] A_Index is a built in counter for Loops.
SendInput % MyArray[A_Index]
Sleep 50
SendInput {Enter}
}
希望这对您有所帮助。
在一个循环中我想使用一个计数器来使用不同的变量。 问题是两者都使用 % 符号:%VAR%
显示错误 %%,已简化:
textGH1 = Peter
textGH2 = rocks.
i = 1
Loop, 2
{
SendInput {Enter}
Sleep 50
SendInput, %textGH%i%%
Sleep 50
SendInput {Enter}
i++
}
错误:空变量引用 %%
我尝试了什么: 我已经查找了 autohotkey 的数组,但我只找到了 使用 %COUNTER% 作为解决方法的伪数组,类似于我的方法 做到了。其次,我已将循环中的一个变量分配给您当前的变量:
text := textGH%i%
然而,这并没有像预期的那样调用变量(再次需要 %textGH%i%%)
这应该有效:
SendInput, %textGH%%i%
我想我明白你在做什么?当计数器改变时交换变量。最简单的方法是使用数组。
这里有一个解决方案供您尝试:
Define Array. Array's Index values automatically, so Peter is at Index 1 Rocks is at Index 2.
MyArray := ["Peter", "Rocks"]
Loop amount of times as there are Values in your Array.
Loop, % MyArray.MaxIndex() {
SendInput {Enter}
Sleep 50
Send your Array at [Index] A_Index is a built in counter for Loops.
SendInput % MyArray[A_Index]
Sleep 50
SendInput {Enter}
}
希望这对您有所帮助。