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 

Trouble using a variable in a loop.

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



Joined: 27 Feb 2008
Posts: 20

PostPosted: Tue Mar 11, 2008 3:34 pm    Post subject: Trouble using a variable in a loop. Reply with quote

Hi. I'd like to create a loop that does {DOWN} everytime it enters. I'd like to enter it as many times as the number copied into the clipboard says -1.
This is what I wrote, however, it does not go down even once. Seems to not enter the loop at all.
Loop, (clipboard-1)
{Send, {DOWN}
}

I've tried to remove the -1 and it still didn't work, however when I used the number 5 instead of a variable it worked.
Any ideas are greatly appreciated.
Regards,
Andy
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Tue Mar 11, 2008 3:49 pm    Post subject: Reply with quote

Code:
Clipboard = 5 ; example value
LoopTimes:=Clipboard - 1
Loop, %Looptimes%
{
Send, {DOWN}
}

Works for me[/code]
Back to top
View user's profile Send private message
MetuZ



Joined: 03 Mar 2008
Posts: 26

PostPosted: Tue Mar 11, 2008 3:50 pm    Post subject: Reply with quote

I don't know much about clipboards yet, but..

Loop, (clipboard-1)
{
Send, {DOWN}
}
return

Would make more sense.
Back to top
View user's profile Send private message
pt80chip



Joined: 27 Feb 2008
Posts: 20

PostPosted: Tue Mar 11, 2008 3:58 pm    Post subject: Reply with quote

HugoV, I copied your code but it doesn't seem to work for me. Still doesn't enter the loop
Back to top
View user's profile Send private message
Absolut Xero



Joined: 11 Mar 2008
Posts: 4
Location: Midland, MI

PostPosted: Tue Mar 11, 2008 4:01 pm    Post subject: Reply with quote

HugoV had what I could find as the easiest way to do it.

I think the problem with yours is that the Loop command does not translate the variable-1. I don't know if that is the case, just a thought.
_________________
"We in America do not have government by the majority. We have government by the majority who participate."
Thomas Jefferson
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Tue Mar 11, 2008 4:05 pm    Post subject: Reply with quote

Code:
Clipboard = 5
MsgBox %Clipboard%
LoopTimes:=Clipboard - 1
Loop, %Looptimes%
{
Send, {DOWN}
}

This will display the clipboard contents, if it doesn't enter the loop
the contents of the clipboard might not be correct something like 5,00

If I copy the script above it works for me.
Back to top
View user's profile Send private message
pt80chip



Joined: 27 Feb 2008
Posts: 20

PostPosted: Tue Mar 11, 2008 4:11 pm    Post subject: Reply with quote

OK, when I copied your script, it worked as planned. Message came up as 5, and ran the loop 4 times.
However, when I remove Clipboard=5, it doesn't work.
the msgbox still says 5, but it does not enter the loop. The reason I need to get the information from the clipboard is because I am copying it from a spreadsheet. Doing clipboard=5 would mean that for every line in the spreadsheet I have to change the code.
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Tue Mar 11, 2008 4:20 pm    Post subject: Reply with quote

That would be correct, as the clipboard contains a newline character you can not
do the math Smile
try this
Code:
StringReplace,Clipboard,Clipboard,`r`n,,all
LoopTimes:=Clipboard - 1
MsgBox %Looptimes%
Loop, %Looptimes%
{
Send, {DOWN}
}

The stringreplace removes any newline from the clipboard, tested and works for me
Back to top
View user's profile Send private message
Absolut Xero



Joined: 11 Mar 2008
Posts: 4
Location: Midland, MI

PostPosted: Tue Mar 11, 2008 4:20 pm    Post subject: Reply with quote

How are you getting the number for the loop to the clipboard? How are you triggering the loop?
_________________
"We in America do not have government by the majority. We have government by the majority who participate."
Thomas Jefferson
Back to top
View user's profile Send private message
pt80chip



Joined: 27 Feb 2008
Posts: 20

PostPosted: Tue Mar 11, 2008 4:23 pm    Post subject: Reply with quote

I am copying the number from a spreadsheet. I did
Send, {ALTDOWN}{TAB}{ALTUP}{RIGHT} to get to the spreadsheet and to the correct cell, then
Send, {CTRLDOWN}c{CTRLUP}
The funny thing is that the msgbox still displays the same thing for clipboard but interprets it differently
Back to top
View user's profile Send private message
pt80chip



Joined: 27 Feb 2008
Posts: 20

PostPosted: Tue Mar 11, 2008 4:32 pm    Post subject: Reply with quote

HUGOV!! You got it!

Thanks A LOT!!

It was the enter character
Back to top
View user's profile Send private message
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