Jump to content

"for" Loop Executed In A "while"


Recommended Posts

I want to perform a certain operation in a loop using "For" function but only if a certain window is active.

$Iterations=1
WinActivate ("blablabla")
While WinActive ("BlaBlaBla")
    For $Loop=1 To $Iterations
  Send ("abcd")
    Next
Wend

Why the "For" loop is not terminated after only 1 iteration? :whistle:

Link to comment
Share on other sites

  • Administrators

What are you trying to do? Do you never want to send keystrokes to that window again after the first time (even though it will still be active)? Do you need the while loop or would an IF be correct?

$Iterations=1
WinActivate ("blablabla")
If WinActive ("BlaBlaBla") Then
  For $Loop=1 To $Iterations
   Send ("abcd")
  Next
EndIf

Link to comment
Share on other sites

Well, the "IF" is not good enoght.

I want to send lots of text to a window but I'm afraid this window will not be in Focus and all the text will be entered elsewhere. So a "While" will give me the constant ability to stop sending the text in a case that the target window is not active. Get it?

Link to comment
Share on other sites

  • Administrators

Hmm, the If still looks OK for me based on that description..

Let's try this way:

1. How many times do you want to send the text?

2. What do you want to happen if the window loses focus? Stop the script? Wait until it's active again? MsgBox error? Nothing? :whistle:

Link to comment
Share on other sites

  • Administrators

WinActivate("blablah")
For $Loop = 1 to 100
  While Not WinActive("blablah")
    Sleep(10)
  Wend
  Send("abcd")
Next

Or you could have a line to force the window to be active during the for loop.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...