Jump to content
Sign in to follow this  
BlueScreen

"for" Loop Executed In A "while"

Recommended Posts

BlueScreen

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:

Share this post


Link to post
Share on other sites
BlueScreen

Right. So how can I do it right?

Share this post


Link to post
Share on other sites
Jon

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

Share this post


Link to post
Share on other sites
BlueScreen

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?

Share this post


Link to post
Share on other sites
Jon

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:

Share this post


Link to post
Share on other sites
BlueScreen

Well, I want to send the text 100 times, and when the window gets out of focus, I want the script to resume when the window gets back to focus... :whistle:

Share this post


Link to post
Share on other sites
BlueScreen

10x, Jon. It is working well. :whistle:

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.