| View previous topic :: View next topic |
| Author |
Message |
pt80chip
Joined: 27 Feb 2008 Posts: 20
|
Posted: Tue Mar 11, 2008 3:34 pm Post subject: Trouble using a variable in a loop. |
|
|
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 |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Tue Mar 11, 2008 3:49 pm Post subject: |
|
|
| Code: | Clipboard = 5 ; example value
LoopTimes:=Clipboard - 1
Loop, %Looptimes%
{
Send, {DOWN}
} |
Works for me[/code] |
|
| Back to top |
|
 |
MetuZ
Joined: 03 Mar 2008 Posts: 26
|
Posted: Tue Mar 11, 2008 3:50 pm Post subject: |
|
|
I don't know much about clipboards yet, but..
Loop, (clipboard-1)
{
Send, {DOWN}
}
return
Would make more sense. |
|
| Back to top |
|
 |
pt80chip
Joined: 27 Feb 2008 Posts: 20
|
Posted: Tue Mar 11, 2008 3:58 pm Post subject: |
|
|
| HugoV, I copied your code but it doesn't seem to work for me. Still doesn't enter the loop |
|
| Back to top |
|
 |
Absolut Xero
Joined: 11 Mar 2008 Posts: 4 Location: Midland, MI
|
Posted: Tue Mar 11, 2008 4:01 pm Post subject: |
|
|
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 |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Tue Mar 11, 2008 4:05 pm Post subject: |
|
|
| 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 |
|
 |
pt80chip
Joined: 27 Feb 2008 Posts: 20
|
Posted: Tue Mar 11, 2008 4:11 pm Post subject: |
|
|
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 |
|
 |
HugoV
Joined: 27 May 2007 Posts: 650
|
Posted: Tue Mar 11, 2008 4:20 pm Post subject: |
|
|
That would be correct, as the clipboard contains a newline character you can not
do the math
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 |
|
 |
Absolut Xero
Joined: 11 Mar 2008 Posts: 4 Location: Midland, MI
|
Posted: Tue Mar 11, 2008 4:20 pm Post subject: |
|
|
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 |
|
 |
pt80chip
Joined: 27 Feb 2008 Posts: 20
|
Posted: Tue Mar 11, 2008 4:23 pm Post subject: |
|
|
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 |
|
 |
pt80chip
Joined: 27 Feb 2008 Posts: 20
|
Posted: Tue Mar 11, 2008 4:32 pm Post subject: |
|
|
HUGOV!! You got it!
Thanks A LOT!!
It was the enter character |
|
| Back to top |
|
 |
|