 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
leuce
Joined: 17 May 2006 Posts: 23 Location: Johannesburg, ZA
|
Posted: Wed May 17, 2006 7:46 pm Post subject: How to loop a limited number of times |
|
|
G'day
This may seem like a stupid question, but I can't get it to work. I have a variable called k1, which contains the number 50. I want a loop to loop 50 times (in other words, k1 times). How do I do this?
I have tried, unsuccessfully, the following:
| Code: |
k3 = %k1%
Loop
{
Send, {tab}
Sleep, 50
k3 -= 1
if k3 < 0
break
}
MsgBox, The End
|
| Code: |
Loop, k1
{
Send, {tab}
Sleep, 50
}
MsgBox, The End
|
| Code: |
Loop k1
{
Send, {tab}
Sleep, 50
}
MsgBox, The End
|
| Code: |
Loop, %k1%
{
Send, {tab}
Sleep, 50
}
MsgBox, The End
|
| Code: |
Loop, % k1 +1
{
Send, {tab}
Sleep, 50
}
MsgBox, The End
|
...but in all the above cases, the loop just goes on and on and on.
If I can't figure this out, I'm gonna call an AutoIt EXE file for the loop, and then return to AutoHotKey for some of the other functions.
Thanks in advance.
Samuel |
|
| Back to top |
|
 |
Aybra
Joined: 16 May 2006 Posts: 58
|
Posted: Wed May 17, 2006 8:15 pm Post subject: |
|
|
| Code: |
^4::
sleep, 1000
k1 = 15
k3 = %k1%
Loop
{
Send, %k3%`n
Sleep, 50
k3 -= 1
if k3 < 0
break
}
MsgBox, The End
|
this prints 15-0, .. then breaks |
|
| Back to top |
|
 |
TeknoMusicMan
Joined: 14 Apr 2005 Posts: 188 Location: Wisconsin, USA
|
Posted: Wed May 17, 2006 8:21 pm Post subject: |
|
|
I ran the following code to test the loop.
| Code: | k1 = 10
num = 1
loop %k1%
{
msgbox, %num%
num += 1
}
|
Is that all of your code? maybe your variable is somehow being read as a string instead of a number?
you could try looking at the SetFormat command. _________________
"Make it idiot-proof, and someone will make a better idiot." |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2436
|
Posted: Thu May 18, 2006 5:10 am Post subject: |
|
|
Are you using a hotkey to start this code? If yes, which one? Tab? Does the code above and below this code end with a Return line? Which version of AutoHotkey are you using? Tested ok here:
| Code: | ~Tab::
k1 = 49
Loop, %k1%
{
Send, {tab}
Sleep, 50
}
MsgBox, The End
Return
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|