AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to loop a limited number of times

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
leuce



Joined: 17 May 2006
Posts: 23
Location: Johannesburg, ZA

PostPosted: Wed May 17, 2006 7:46 pm    Post subject: How to loop a limited number of times Reply with quote

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
View user's profile Send private message Visit poster's website
Aybra



Joined: 16 May 2006
Posts: 58

PostPosted: Wed May 17, 2006 8:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
TeknoMusicMan



Joined: 14 Apr 2005
Posts: 188
Location: Wisconsin, USA

PostPosted: Wed May 17, 2006 8:21 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Thu May 18, 2006 5:10 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group